C# 中 List 用法
来源:互联网 发布:sony音乐播放软件 编辑:程序博客网 时间:2024/04/28 01:50
List 类是 ArrayList 类的泛型等效类,某些情况下,用它比用数组和 ArrayList 都方便。
我们假设有一组数据,其中每一项数据都是一个结构。
public struct Item
{
public int Id;
public string DisplayText;
}
{
public int Id;
public string DisplayText;
}
注意结构是不能给实例字段赋值的,即 public int Id = 1 是错误的。
using System.Collections.Generic;
List<Item> items = new List<Item>();
//添加
Item item1 = new Item();
item1.Id = 0;
item1.DisplayText = "水星";
items.Add(item1);
//添加
Item item2 = new Item();
item2.Id = 1;
item2.DisplayText = "地球";
items.Add(item2);
//修改
//这里使用的是结构,故不能直接用 items[1].DisplayText = "金星";,如果 Item 是类,则可以直接用。为什么呢?因为结构是按值传递的。
Item item = items[1];
item.DisplayText = "金星";
items[1] = item;
List<Item> items = new List<Item>();
//添加
Item item1 = new Item();
item1.Id = 0;
item1.DisplayText = "水星";
items.Add(item1);
//添加
Item item2 = new Item();
item2.Id = 1;
item2.DisplayText = "地球";
items.Add(item2);
//修改
//这里使用的是结构,故不能直接用 items[1].DisplayText = "金星";,如果 Item 是类,则可以直接用。为什么呢?因为结构是按值传递的。
Item item = items[1];
item.DisplayText = "金星";
items[1] = item;
- C#中List用法
- C#中List用法
- C# 中 List 用法
- C# 中 List 用法
- C#中List用法
- C#中list用法
- c#中List基本用法
- C#中List的排序用法(Sort)
- C#中List的排序用法(Sort)
- C#中List的排序用法(Sort)
- 关于C#中list的用法
- C#中List的排序用法(Sort)
- C#中List<T>的用法
- C# List<T>中Find的用法
- C#中List怎么用?List基础用法汇总
- C#中List怎么用?List基础用法汇总
- C# List 用法
- C# List 用法
- Oracle执行计划的相关概念
- 对ioc和di的理解
- 要开始学习Java了!
- 转载:十句话
- java学习之路1
- C# 中 List 用法
- stuff 解析
- 数据库无法打开
- 函数
- 算法问题:什么是P问题、NP问题和NPC问题
- IO流与序列化
- 自制电子鼓项目开源
- Anobiit:條碼掃瞄 + 網路書櫃應用
- 网站重构