What I see here is an attempt to use an Array of Anonymous Types, not a use of the Expando in the System.Dynamic Library: big difference !
Further, since your Array elements here are Anonymous Types which are not themselves Enumerable ... i.e. not Arrays, for example ... there's no way you can iterate over each element to access all the internal Fields, to do what you describe you want to do.
You can, of course, iterate over an Array of Anonymous Types where you have properly named each internal Type, and access all Types by their Name. That means, if you wish to parse every field you will have to check every field, and if you have fields of different Types, then you may have to do conversion of Types.
While you could use some form of Reflection to access the internal Fields: [
^], that requires very advanced programming.
Further, if you wish to save (serialize) an Anonymous Type, to XML for example, you are going to have to use quite exotic code: [
^].
For many reasons, including the above, I'd advise you
not to use Anonymous Types ... unless you are a very advanced .NET programmer, and willing to pay a possibly high price in terms of use of computational resources and time.
MSDN for Visual Studio 2013:
"Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first. The type name is generated by the compiler and is not available at the source code level. The type of each property is inferred by the compiler."
[
^].
Note that Anonymous Types are "immutable"(implied by the term read-only). Also note that the compiler while processing an Array of Anonymous Types will do internal type-checking: see the note at the end here.
First, let's get whatever you are trying to do to compile.
This is what an Array of Anonymous Types would look like in C#:
var records = new[]
{
new
{
Id = 1,
Name = "sai",
Age = "4",
About = "12.02.1991"
},
new
{
Id = 2,
Name = "hjfh",
Age = "2",
About = "12.02.1991"
},
new
{
Id = 3,
Name = "hello name",
Age = "6",
About = "hi"
},
new
{
Id = 4,
Name = "1",
Age = "9",
About = "hello world"
}
};
Note that if you change the Type of one of the Fields of the Anonymous Type here; for example:
new
{
Id = 4,
Name = 1;
Age = "9",
About = "hello world"
}
Here we changed the Type of the Name Property to an Int from a String.
After this change, this will not compile: the compiler, trying to construct a sequence of internal Types, enforces Type consistency by inferring the internal Types from the Type structure, so it can't handle any variance in Type declaration ! This kind of bug can be quite confusing to encounter.