Passing a 'var' into another method
Posted
by Danny
on Stack Overflow
See other posts from Stack Overflow
or by Danny
Published on 2010-03-28T16:24:44Z
Indexed on
2010/03/28
16:33 UTC
Read the original article
Hit count: 284
Hi,
I am probably totally missing the point here but....
How can I pass a 'var' into another method?
(I am using linq to load XML into an Enumerable list of objects).
I have differernt object types (with different fields), but the final step of my process is the same regardless of which object is being used.
XNamespace xmlns = ScehmaName;
var result = from e in XElement.Load(XMLDocumentLocation).Elements(xmlns + ElementName)
select new Object1
{
Field1 = (string)e.Element(xmlns + "field1"),
Field2 = (string)e.Element(xmlns + "field2")
};
var result2 = Enumerable.Distinct(result);
This code will vary for the different type of XML files that will be processed. But I then want to iterate though the code to check for various issues:
foreach (var w in result2)
{
if (w.CheckIT())
{
//do something
}
}
What I would love is the final step to be in a method in the base class, and I can pass the 'var' varible into it from each child class.
© Stack Overflow or respective owner