C# syntax to initialize custom class/objects through constructor params in array?
Try adding square brackets after new MyClass and a semi-colon at the end
MyClass[] testobjlist = new MyClass[]
{
new MyClass(1001,1234,"Text 1", "abcdefghijklm", "ding"),
new MyClass(1002,2345,"Text xx", "bla bla", "dong"),
new MyClass(1003,8653,"Text yy", "blah blah even more", "bamm!")
};
this will also work without a need to create a constructure
new MyClass [] { new MyClass { Field1 = "aa", Field2 = 1 } }
Shorthand for the win:
var myClassList = new[]
{
new MyClass(1001,1234,"Text 1", "abcdefghijklm", "ding"),
new MyClass(1002,2345,"Text xx", "bla bla", "dong")
};