c# Cannot use ref or out parameter inside an anonymous method

Error      1      Cannot use ref or out parameter 'c' inside an anonymous method, lambda expression, or query expression      E:\strucccc\strucccc\Program.cs      80      76      strucccc


Hello,

i have a problem with my code in c# if someone could help resolve my problem.

In a function i am parsing an Xml file and saving it to a struct.

Then i try to retreive some info from said struct with specific node id and my code fails with

"Cannot use ref or out parameter 'c' inside an anonymous method, lambda expression, or query expression"

Here is my code:
public void XmlParser(ref Point a, ref Point b, ref Point c)
         {

             XDocument xdoc = XDocument.Load(XmlDirPath);

             var coordinates = from r in xdoc.Descendants("move")
                               where int.Parse(r.Attribute("id").Value) == c.NodeID  // !! here is the error !!
                     
                               select new
                               {
                                   X = r.Element("x").Value,
                                   Y = r.Element("y").Value,
                                   Z = r.Element("z").Value, 
                                   nID = r.Attribute("id").Value

                               };

             foreach (var r in coordinates)
             {
                 c.x = float.Parse(r.X1, CultureInfo.InvariantCulture);
                 c.y = float.Parse(r.Y1, CultureInfo.InvariantCulture);
                 c.z = float.Parse(r.Z1, CultureInfo.InvariantCulture);
                 c.NodeID = Convert.ToInt16(r.nID);
             }
             
         }

		 
	 public struct Point
        {
            public  float x;
            public  float y;
            public  float z;
            public  int   NodeID;
        }	 
		

Open in new window

           
Thanks for reading!
TagyourareitAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
I cannot test right now, but I would do this:

public void XmlParser(ref Point a, ref Point b, ref Point c)
         {
             int cNodeID = c.NodeID
             XDocument xdoc = XDocument.Load(XmlDirPath);

             var coordinates = from r in xdoc.Descendants("move")
                               where int.Parse(r.Attribute("id").Value) == cNodeID
 ....
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TagyourareitAuthor Commented:
Thank you!

Its var i = c.NodeiD but you were on point.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.