CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2014
    Posts
    2

    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
    Code:
    (o = object) v
    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!

  2. #2
    Join Date
    Apr 2014
    Posts
    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
  •  





Click Here to Expand Forum to Full Width

Featured