c# – 检查数组是空还是空?
发布时间:2020-12-15 17:50:59 所属栏目:百科 来源:网络整理
导读:我在这行代码中有一些问题: if(String.IsNullOrEmpty(m_nameList[index])) 我做错了什么? 编辑:在VisualStudio中,m_nameList带有红色下划线,并且说“在当前上下文中不存在名称”m_nameList“? 编辑2:我添加了一些更多的代码 class SeatManager{ // Fiel
我在这行代码中有一些问题:
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#LIifxNet切换光功率,LIFX
- 什么使PostgreSQL比MySQL更高级?
- ruby-on-rails – 如何使用Rails 3停止<%= strings%>的
- c# – 实体框架中的简单条件LINQ查询4
- c# – 如何在WCF中使用DataContract / DataMember序列化Fun
- Serialize and deserialize objects as Xml using generic
- ruby-on-rails – Ruby版本> = X与当前版本不兼容
- ruby-on-rails – 使用Fog AWS S3和Rails时获得负到期
- React的生命周期与应用
- 跟着设计哲学走:React数据绑定和获取,别闯红灯