-
June 13th, 2019, 12:01 AM
#1
Anonymous Object Newbie Query
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!
-
June 13th, 2019, 12:02 AM
#2
Re: Anonymous Object Newbie Query
* o = (object) v
Where's the edit post button???
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|