anonymous object
If you define an object like:
var test = new { firstParam = "testing", secondParam = "testing" };
Is there a way of iterating over the parameters? Something like
foreach(Param p in test)
{
//do something
}
Thanks for any help.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jake HallonPosted Apr 29, 2009, 5:58 PM
var test = new { action = "testing", test = "another" };
System.Reflection.PropertyInfo[] infoArray = test.GetType().GetProperties();
string tmp = "";
foreach (System.Reflection.PropertyInfo info in infoArray)
{ tmp += info.Name + " | " + info.GetValue(test, null); }
Jake HallonPosted Apr 29, 2009, 5:31 PM
Kumar AGPosted Apr 29, 2009, 4:39 PM
object
[] test = {"testing","testing2","testing3"}; foreach (object obj in test) Console.WriteLine(obj.ToString());