Reputation: 15
I'm trying to loop through the results of a function that is returning an anonymous object of results.
public static object getLogoNav()
{
XDocument loaded = XDocument.Load(HttpContext.Current.Request.MapPath("~/App_Data/LOGO_NAV_LINKS.xml"));
var query = from x in loaded.Elements().Elements()
select new
{
Name = x.FirstAttribute.Value,
Value = x.Value
};
return query;
}
codebehind page:
var results = Common.getLogoNav();
foreach(var nav in results) {
string test = nav.Name;
}
Upvotes: 1
Views: 1001
Reputation: 121304
You can't have an anonymous class as a return type in C# 3 (and 4 for that matter) and you can't cast an object to an anonymous type. Your three options are:
Upvotes: 5
Reputation: 68667
Jon Skeet wrote an entry about returning anonymous type. I hope you don't use it.
Upvotes: 2