Hi there
I'm starting to learn C# and am trying to understand how Anonymous Objects work. The code below will not compile because "Object does not contain a definition for Name". My understanding was that an anonymous classes were children of the object class. Since the compiler allowed me to type o=v, then o references the anonymous object v. Why can't I read its name then? I tried to cast v to object using but it made no difference...?
Code:
static void Main(string[] args)
{
var v = new {Name= "Nigel", Age = 50};
object o;
o = v;
Console.WriteLine(o.Name);
}
Thank you for your time!