我目前有以下代码:
public int GetSeatInfoString(DisplayOptions choice, out string[] strSeatInfoStrings)
public int GetSeatInfoString(DisplayOptions choice, out string[] strSeatInfoStrings)
{
strSeatInfoStrings = null;
int count = GetNumOfSeats(choice);
if ((count <= 0))
return 0;
strSeatInfoStrings = new string[count];
int i = 0;
for (int index = 0; index <= m_totNumOfSeats - 1; index++)
{
if (string.IsNullOrEmpty(m_nameList[index]))
strSeatInfoStrings[i++] =
m_nameList[index].ToString();}
m_nameList[index].ToString(); }
}
此代码产生错误...GetSeatInfoString.DisplayOptions, out string[])":并非所有代码路径都返回一个值.基本上,我希望在上述方法中执行的操作是循环一个数组和数组中包含字符串的任何值,我希望将它们添加到新数组中,strSeatInfoStrings 反过来可以从单独的类中调用,然后新的数组内容显示在列表框中.
This code produces an error of, "...GetSeatInfoString.DisplayOptions, out string[])': not all code paths return a value. Basically, what I am looking to do in the above method is to cycle through an array and for any values in the array that contain a string, I want these then adding to the new array, strSeatInfoStrings which in turn, can be called from a separate class and the new array content then displayed in a listbox.
关于如何纠正此问题的任何建议?
Any suggestions on how to rectify this?
提前致谢
可以在末尾加上 return strSeatInfoStrings.Length
You can add return strSeatInfoStrings.Length
at the end
public int GetSeatInfoString(DisplayOptions choice, out string[] strSeatInfoStrings)
{
strSeatInfoStrings = null;
int count = GetNumOfSeats(choice);
if ((count <= 0))
return 0;
strSeatInfoStrings = new string[count];
int i = 0;
for (int index = 0; index <= m_totNumOfSeats - 1; index++)
{
if (string.IsNullOrEmpty(m_nameList[index]))
strSeatInfoStrings[i++] =
m_nameList[index].ToString(); }
return strSeatInfoStrings.Length;
}
这篇关于C# - 错误“并非所有代码路径都返回值";以数组作为输出参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!