Is there an easy way to create and Object and set properties in C# like you can in Javascript.
Example Javascript:
var obj = new Object;
obj.value = 123476;
obj.description = "this is my new object";
obj.mode = 1;
Is there an easy way to create and Object and set properties in C# like you can in Javascript.
Example Javascript:
var obj = new Object;
obj.value = 123476;
obj.description = "this is my new object";
obj.mode = 1;
try c# anonymous classes
there are lots of differences though...
@Valera Kolupaev & @GlennFerrieLive mentioned another approach with dynamic keyword
In case, if you want to create un-tyed object use ExpandoObject.
Your other option is to use anonymous class , but this will work for you, only if you would use it in the scope of the method, since the object type information can't be accessed from outside of the method scope.
The way to do this is you use C# 4.0 Dynamic types like Expando Object... see this topic:
How to create a class dynamically
In C# you could do:
EDIT: Holding this here pending clarification from OP as I may have misunderstood his intentions.