jeudi 23 avril 2015

I'm coding some test methods and have not been able to initialize a test List and receive the error "Can only use array initializer expressions to assign to array types. Try using a new expression instead." I have tried to initialize the List in every way that should be possible to do so, i.e.

List<string> testPaths = new List<string>() {
            "testData"
        };

string[] testFilePathsArray = 
        {
           "testData"
        };
var testFilePaths = new List<string>(testFilePathsArray);

var testPaths = new List<string>() {
            "testData"
        };

var testPaths = new List<string>();
testPaths.Add("testData");

List<string> testPaths = new List<string>();
testPaths.Add("testData");

etc., and none of them give anything but this error. What is the cause of this error, especially when I am using one of the solutions where arrays are not even used? I understand the differences between arrays and lists, but even using the Add method returns this error.

Aucun commentaire:

Enregistrer un commentaire