I was working on javascript before.
In javascript, I do this to create dynamic object and assign properties to it.
var house = new object();
house.kitchen = 1;
house.bedroom = 2;
house.livingroom =3;
How to do the same stuff in C#?
I was working on javascript before.
In javascript, I do this to create dynamic object and assign properties to it.
var house = new object();
house.kitchen = 1;
house.bedroom = 2;
house.livingroom =3;
How to do the same stuff in C#?
in C# there is something called dynamic
that you could use
dynamic house = new ExpandoObject();
house.Kitchen = 1;
house.Bedroom = 2;
house.Livingroom =3;
but if I am new to c# that is not were I would start, dynamic
has very specific uses, typically in more advanced situations. What you really should be looking at is Classes and objects. C# is a static language, and dynamic is there just to give it a bit more flexibility.
I'd guess that you're looking for something like the ExpandoObject in C#. See this question for details on how to use it. Basically, it allows you to add properties to objects at runtime in a manner similar to Javascript. Please note, however, that idiomatic C# doesn't make much use of it.
The analogous C# code for your JavaScript example would be something like this:
dynamic house = new ExpandoObject();
house.kitchen = 1;
house.bedroom = 2;
house.livingroom = 3;