pre generated static Object in C#

i need static property, which will be more or less complicated object, which propertis might be array, float, int and string

in flash/as3 i would do it by json:

static Object o = {property:1, property2:{subproperty:“text”, subproperty:[{subP:1, subP:2}]}};

is there way in c# ?

Do you mean it can contain any properties? Isn't it possible to define a class with all possible properties and fill only part of them when initializing? If it's possible, then you can initialize an instance by deserializing JSON.

1 Answer

1

you can use constructors in your Object to achieve this

public class MyObject {
string text;
float num;
int num2;
int[] sub; 


public MyObject(string text, float num, int num2, int[] subprop) {
 this.text = text;
this.num = num;
this.num2 = num2;
this.sub = subprop;
//code goes here

}}

to create the static object, you can now use this constructor

static MyObject obj = new MyObject("blurzdfasdf", 69f, 69, new int[] {6,9});

is there way to do it without particular Class but only with Object ? i mean, this works, but is there way to do it as in AS3 with JSON?

too bad well the 1st answer works well for my case, i just wanted to know if it's possible ... i miss JSON the native way it works in AS3 thx a lot guys!