As an ArrayList
does not make any assumptions on the data includued you can add any datatype to it. To do so there are several possibilites, e.g. using an object-initializer:
var game = new PlatanoJson {
question = "What is your education?",
correctans = "MCA",
typeofans = true,
indexofque = 3,
DiffAns = new ArrayList { 1, 2, 3, "myString" }
};
Alternatively you can also use the constrcutor expecting an ICollection
:
DiffAns = new ArrayList(new object[] { 1, 2, 3, "myString" })
However I would recommend to go with time and use the egeneric appraoches instead. With ArrayList
you have no way to constraint which objects your list may contain, you can (as you can see in the code above) put inetegeres, strings and any different datatype into it. Better use List<T>
which gives you compile-time type-security:
var game = new PlatanoJson {
question = "What is your education?",
correctans = "MCA",
typeofans = true,
indexofque = 3,
DiffAns = new List<int>{ 1, 2, 3 } // you van´t put a string into this list
};