I have a class that assigns a string property in the constructor, thus:
I'm attempting to create an array of this class. I first attempted it this way:
but the compiler thinks I'm trying to cast the strings as object references. I find that this works fine:
but it's tedious and inelegant. Is there a cleaner way to do this?
TIA
Code:
public class Test
{
public string StrProp {get; set;}
public Test(string myString)
{
StrProp = myString;
}
}
I'm attempting to create an array of this class. I first attempted it this way:
Code:
Test[] myTests = new Test[7]; { "Anne", "Bob", "John" };
Code:
Test[] myTests = new Test[7];
myTests[0] = new Test("Anne");
myTests[1] = new Test("Bob");
myTests[2] = new Test("John");
TIA