C#中“数组初始值设定项只能在变量或字段初始值设定项中使用,请尝试使用new表达式”

2024-12-03 14:10:21
推荐回答(2个)
回答1:

Novelists是数组的数组,有点绕口,哈
string[][] Novelists = new string[3][]
先声明一个包含三个数组元素的数组,没问题,然后再对数组元素分别初始化
string[,] Novelists = new string[3,3] { { "fyodor", "mikljalfjdal", "aslfjewqp" } ,
{ "jaoie", "cipejide", "iwhoxaslfjewqp" },{ "iemcurdor", "miasdfakljalfjdal", "lwekrj" }};

回答2:

string[][] Novelists = new string[3][3] { { "fyodor", "mikljalfjdal", "aslfjewqp" } ,
{ "jaoie", "cipejide", "iwhoxaslfjewqp" },{ "iemcurdor", "miasdfakljalfjdal", "lwekrj" }};