Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#NullReferenceException未处理(使用字符串数组)_C# - Fatal编程技术网

C#NullReferenceException未处理(使用字符串数组)

C#NullReferenceException未处理(使用字符串数组),c#,C#,我有以下代码: string[] buttons = new buttons[5]; int j = 0; while (j<5) { buttons[j] = pullString(node); j++; } string[]按钮=新按钮[5]; int j=0; 而(j我猜pullString方法引发了这个异常。因为您在问题中没有展示这个方法的主体,这是迄今为止您能得到的最佳答案。更不用说下面这一行了: string[] buttons

我有以下代码:

string[] buttons = new  buttons[5];
int j = 0;
while (j<5)

    {
       buttons[j] = pullString(node);
       j++;
    }
string[]按钮=新按钮[5];
int j=0;

而(j我猜
pullString
方法引发了这个异常。因为您在问题中没有展示这个方法的主体,这是迄今为止您能得到的最佳答案。更不用说下面这一行了:

string[] buttons = new  buttons[5];

需要对C#编译器进行一些调整才能进行编译(当然,除非您已经为字符串类型定义了别名:
使用buttons=System.string;
,我对此深表怀疑)。

假设应该这样做

string[] buttons = new string[5];

NullReferenceException
是由
pullString(node)
引发的,其他一切都很好。

请复制并粘贴您的代码。这甚至不会编译。我怀疑您是否真的有
string[]buttons=新按钮[5]
为什么要使用while循环并递增一个变量?只使用常规for循环难道不更有意义吗?在“使其静音”时,发布
pullString()
@Zack的代码一定要把它简化为编译的东西,并且仍然显示出问题所在。把它简化到任何人都能帮助你的地步是没有用的。