Interview question - anonymous types

I've been reading about anonymous types and I think the answer to this question is the 4th one "new class with properties both set and get methods". Saw an explanation on a site but forgot to bookmark it

b3.png
LVL 8
CamilliaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gr8gonzoConsultantCommented:
Gotta love it when people try intentionally to screw you up by giving you two very close answers.

The answer is #3 - with only get methods.  

This seems like a terrible interview question, though. Usually means the interviewer is trying to test your academic knowledge instead of practical knowledge, which doesn't help when you get into the job itself (unless your job is to build a compiler).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kaufmed   ( ⚆ _ ⚆ )I asked the operating system what I could do to become a better programmer. It said, "Let me give you some pointers."Commented:
You cannot assign to the properties that are defined on an anonymous type, therefore the properties are "get" only. And anonymous types are always classes.
CamilliaAuthor Commented:
Thanks, guys. Taking tests are becoming routine for job interviews now, seems like it.
it_saigeDeveloperCommented:
A new class with properties and only get methods.  Proof of concept -
using System;

namespace EE_Q29137622
{
    class Program
    {
        static void Main(string[] args)
        {
            var paul = new { ID = 1, FirstName = "Paul", LastName = "Tester", IsWorking = true };
            Console.WriteLine($"paul is a {paul.GetType()}");
            Console.WriteLine($"paul's value is {paul}");
            paul.FirstName = "Larry";
            paul.LastName = "Johnson";
            paul.IsWorking = false;
            Console.ReadLine();
        }
    }
}

Open in new window

Produces the following error -Capture.PNGWhile the following:
using System;

namespace EE_Q29137622
{
    class Program
    {
        static void Main(string[] args)
        {
            var paul = new { ID = 1, FirstName = "Paul", LastName = "Tester", IsWorking = true };
            Console.WriteLine($"paul is a {paul.GetType()}");
            Console.WriteLine($"paul's value is {paul}");
            Console.ReadLine();
        }
    }
}

Open in new window

Produces the following output -Capture.PNG-saige-
CamilliaAuthor Commented:
Thanks for the proof of concept. Going to try that. Helps me understand the solution better.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.