【发布时间】:2015-04-08 05:29:53
【问题描述】:
这里我声明了 main 之外的结构
struct webDataStructure
{
public string title;
public string mainLink;
public string numberOfPages;
public List<string> secondaryLinks;
}
在main里面初始化结构
webDataStructure[] webData = new webDataStructure[400];
然后我在 for 循环中的 main 中初始化它
webData[i].secondaryLinks = new List<string>(35);
问题是 Count of List 还是 0,应该是 35
【问题讨论】:
-
List<T>(int)constructor 只允许您指定初始容量,而不是要创建的元素数量。您希望哪些字符串出现在列表中?你确定你需要一个结构而不是一个类吗? -
我也可以使用类,我会将链接存储在字符串中
标签: c# struct initialization