Say I have the code below:
dynamic myData = GetMyData();
foreach(dynamic d in myData.data)
{
Console.WriteLine(d.name);
}
How could I writeout all of the names in alphabetical order? If I were using something like List<MyClass> i would just use myData.OrderBy(t => t.name), but this does not seem to work when I’m using a dynamic type.
Any suggestions to how I can order these values?
That should return the same as
myData.OrderBy(t => t.name)would normally.Since
OrderByis an extension method, it won’t work on dynamic types. See this answer.