
if(String.IsNullOrEmpty(m_nameList[index]))
我做错了什么?
编辑:在VisualStudio中,m_nameList带有红色下划线,并且说“在当前上下文中不存在名称”m_nameList“?
编辑2:我添加了一些更多的代码
class SeatManager{ // FIElds private Readonly int m_totNumOfSeats; // Constructor public SeatManager(int maxnumOfSeats) { m_totNumOfSeats = maxnumOfSeats; // Create arrays for name and price string[] m_nameList = new string[m_totNumOfSeats]; double[] m_priceList = new double[m_totNumOfSeats]; } public int GetNumReserved() { int totalAmountReserved = 0; for (int index = 0; index <= m_totNumOfSeats; index++) { if (String.IsNullOrEmpty(m_nameList[index])) { totalAmountReserved++; } } return totalAmountReserved; } }}解决方法 之后编辑2: 您将m_nameList定义为构造函数的局部变量.
您的其余代码需要它作为一个字段:
class SeatManager{ // FIElds private Readonly int m_totNumOfSeats; private string[] m_nameList; private double[] m_priceList; // Constructor public SeatManager(int maxnumOfSeats) { m_totNumOfSeats = maxnumOfSeats; // Create arrays for name and price m_nameList = new string[m_totNumOfSeats]; m_priceList = new double[m_totNumOfSeats]; } ....} 总结 以上是内存溢出为你收集整理的c# – 检查数组是空还是空?全部内容,希望文章能够帮你解决c# – 检查数组是空还是空?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)