I'm loading a bunch of objects from XML at the start of my main class, into a 'var', using LINQ. I am trying to implement the 'Strategy' pattern in my program though, and I need to reference the 'var' in these strategy classes.
Is there any way I can do this? My understanding is usually I would use static variables, but that doesn't seem to work for 'var'?
XDocument XDoc = XDocument.Load("inventory.xml");
var products = from q in XDoc.Descendants("product")
select new Product
{
RecordNumber = Convert.ToInt32(q.Element("recordNumber").Value),
Name = q.Element("name").Value,
Stock = Convert.ToInt32(q.Element("stock").Value),
Price = Convert.ToInt32(q.Element("price").Value),
CartQuantity = 0,
CartPrice = 0
};
I can attach all of the code if it would be helpful, but I basically just need to know how I can access the 'var' in another class.
No comments:
Post a Comment