加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 我应该使用列表吗?

发布时间:2020-12-16 00:04:11 所属栏目:百科 来源:网络整理
导读:所以目前我有一个多维数组 string[,] items = new string[100,4]; 然后我收集所需的输入以将它们放入数组中,然后将它们显示在列表框中 items[itemcount,0] = id;items[itemcount,1] = newprice;items[itemcount,2] = quant;items[itemcount,3] = desc;listBo
所以目前我有一个多维数组

string[,] items = new string[100,4];

然后我收集所需的输入以将它们放入数组中,然后将它们显示在列表框中

items[itemcount,0] = id;
items[itemcount,1] = newprice;
items[itemcount,2] = quant;
items[itemcount,3] = desc;

listBox1.Items.Add(items[itemcount,0] + "t" + items[itemcount,3] + "t " + items[itemcount,2] + "t " + items[itemcount,1]);
listBox1.SelectedIndex = listBox1.Items.Count - 1;

因此,如果用户想要从列表框中选择一个项目来删除该项目,则用户可以.在删除项目时,我意识到阵列不合适.所以我应该创建4个不同的列表并使用list.Remove方法删除它们或者是否有更好的方法我不需要处理4个不同的东西,用户也在运行使用WinXP的旧计算机我不得不担心表现有4个不同的名单?有没有像多维列表那样的东西?

谢谢你的帮助

解决方法

您正在尝试重新发明类的实例列表.就像是

class Item {
  public int Id {get;set;}
  public double Price {get;set;}
  public double Quantity {get;set;}
  public string Description {get;set;}
}

var myItems = new List<Item>();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读