Javascript “var obj = new Object” Equivalent in C#

前端 未结 4 1952
别跟我提以往
别跟我提以往 2021-02-07 10:49

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 = 123         


        
4条回答
  •  自闭症患者
    2021-02-07 11:14

    In C# you could do:

    var obj = new SomeObject {
        value = 123476,
        description = "this is my new object",
        mode = 1
    };
    

    EDIT: Holding this here pending clarification from OP as I may have misunderstood his intentions.

提交回复
热议问题