×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jul 2013
    Location
    chennai, TN
    Posts
    56

    how to use a linq query in a constructor.

    hi....

    In DetailsModel.cs

    XDocument xdoc = XDocument.Parse(result);

    var details= from ack in xdoc.Descendants()
    where ack.Name == "details"
    select ack;

    In Myclass.cs

    public Myclass()
    {
    // my question is can we able to use a linq query (var details) in this constructor. Is it possible to use in here. P.s let me know
    var details= from ack in xdoc.Descendants()
    where ack.Name == "details"
    select ack;

    }

  2. #2
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    510

    Re: how to use a linq query in a constructor.

    LINQ itself should not be a problem. You will have to make sure that you have actually run the code in DetailsModel.cs before running the code in Myclass.cs (otherwise the document will not have been loaded). Also you will somehow have to make the xdoc field of your DetailsModel class accessible to the code in Myclass.

  3. #3
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: how to use a linq query in a constructor.

    Start with reading the documentation, http://msdn.microsoft.com/en-us/library/bb308960.aspx seems a good one. Then you can go for tutorials, some examples are linked in your earlier discussion already.
    A constructor is method, it can do even more than what normal methods could do. You can freely use LINQ in a constructor.

  4. #4
    Registered User
    Join Date
    Jul 2013
    Location
    chennai, TN
    Posts
    56

    Re: how to use a linq query in a constructor.

    hi...

    how can i pass that linq query variable to that constructor ...let me know
    Last edited by Murugan india; 2013-10-08 at 09:57.

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: how to use a linq query in a constructor.

    Are you asking for
    Code:
    public Myclass(XDocument xdoc)
    {
        var details= from ack in xdoc.Descendants()
        where ack.Name == "details"
        select ack;
    ? Because this is how you pass arguments to a constructor.

  6. #6
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,021

    Re: how to use a linq query in a constructor.

    As per your post in the last discussion thread, Myclass, is simply a setter-getter class (basically model class) of which new object is made everytime the xml data is parsed & it keeps on getting stored in the class (MyClass). There's no need to pass anything in the constructor of this class, you simply need to follow the LINQ to XML architecture & store your data in Myclass.

    You can for example refer this : http://developer.nokia.com/Community...2-6a2dc5898f24

    (Consider FlickrData as your MyClass & notice how that is used when the response xml from server is received)

Similar Threads

  1. pass the URI parameter/value to linq
    By thejeraldo in forum Windows Phone General
    Replies: 4
    Last Post: 2012-02-27, 12:13
  2. bind linq to textblock without listBox.ItemsSource
    By thejeraldo in forum Windows Phone General
    Replies: 2
    Last Post: 2012-02-27, 11:52
  3. Constructor in symbian c++
    By symbian_pinu in forum Symbian
    Replies: 3
    Last Post: 2010-12-10, 13:21
  4. CBase constructor
    By sameer.chaudhari in forum Symbian
    Replies: 2
    Last Post: 2008-05-19, 15:12
  5. Why is this constructor like this?
    By advocatee in forum Symbian
    Replies: 1
    Last Post: 2003-07-02, 16:05

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×