Sss*_*Sss 1 .net c# silverlight dynamic-arrays silverlight-5.0
我正在研究silverligth5(我以前的经验是c ++),我必须创建一个动态数组,其大小是动态决定的.
直到我拥有一切静态,它是这样的:
string[] position = new string[20]; //it must be dynamic I don't want to fix it to 20
for (int i = 0; i < pv.Root.Parameter.Count; i++)
{
if (name == pv.Root.Parameter[i].Name)
{
position[i] = name;
}
}
Run Code Online (Sandbox Code Playgroud)
可以看出,我的方式20只有尺寸,我希望它只有相同的长度 pv.Root.Parameter.Count.
怎么做到这一点?
编辑/当我尝试通过列表实现它时的问题:我在这一行有问题:
if (pv.Root.Parameter[loopCount].Name == position[loopCount])
{
rowGrid.Opacity=0.3;
}
Run Code Online (Sandbox Code Playgroud)
因为它肯定不会起作用,position[loopCount]因为position是List而且不能像这样索引.如何索引呢?
传递pv.Root.Parameter.Count而不是20作为数组长度.
string[] position = new string[pv.Root.Parameter.Count];
Run Code Online (Sandbox Code Playgroud)
如果您不想要固定大小,请使用列表.