C#中的Bulletedlist怎么使用?
答案:2 悬赏:20
解决时间 2021-02-10 00:20
- 提问者网友:白越
- 2021-02-09 11:38
C#中的Bulletedlist怎么使用?
最佳答案
- 二级知识专家网友:茫然不知崩溃
- 2021-02-09 12:23
一、声明:
1、List mList = new List();
T为列表中元素类型,现在以string类型作为例子:
List mList = new List();
2、List testList =new List (IEnumerable collection);
以一个集合作为参数创建List:
string[] temArr = { "Ha", "Hunter", "Tom", "Lily", "Jay", "Jim", "Kuku", "Locu"};
List testList = new List(temArr);
二、添加元素:
1、List. Add(T item)添加一个元素
例:
mList.Add("John");
2、List. AddRange(IEnumerable collection)添加一组元素
例:
string[] temArr = {"Ha","Hunter","Tom","Lily","Jay","Jim","Kuku","Locu"};mList.AddRange(temArr);
3、Insert(intindex, T item);在index位置添加一个元素
例:
mList.Insert(1,"Hei");
三、遍历List中元素:
foreach(TelementinmList)T的类型与mList声明时一样
{
Console.WriteLine(element);
}
例:
foreach(stringsinmList)
{
Console.WriteLine(s);
}
四、删除元素:
1、List. Remove(T item)删除一个值
例:
mList.Remove("Hunter");
2、List. RemoveAt(intindex);删除下标为index的元素
例:
mList.RemoveAt(0);
3、List. RemoveRange(intindex,intcount);
从下标index开始,删除count个元素
例:
mList.RemoveRange(3, 2);
五、判断某个元素是否在该List中:
List. Contains(T item)返回true或false,很实用
例:
if(mList.Contains("Hunter"))
{
Console.WriteLine("There is Hunter in the list");
}
else
{
mList.Add("Hunter");
Console.WriteLine("Add Hunter successfully.");
}
六、给List里面元素排序:
List. Sort ()默认是元素第一个字母按升序
例:
mList.Sort();
七、给List里面元素顺序反转:
List. Reverse ()可以不List. Sort ()配合使用,达到想要的效果
例:
mList.Sort();
八、List清空:
List. Clear ()
例:
mList.Clear();
九、获得List中元素数目:
List. Count ()返回int值
例:
in tcount = mList.Count();
Console.WriteLine("The num of elements in the list: "+count);
1、List
T为列表中元素类型,现在以string类型作为例子:
List
2、List
以一个集合作为参数创建List:
string[] temArr = { "Ha", "Hunter", "Tom", "Lily", "Jay", "Jim", "Kuku", "Locu"};
List
二、添加元素:
1、List. Add(T item)添加一个元素
例:
mList.Add("John");
2、List. AddRange(IEnumerable
例:
string[] temArr = {"Ha","Hunter","Tom","Lily","Jay","Jim","Kuku","Locu"};mList.AddRange(temArr);
3、Insert(intindex, T item);在index位置添加一个元素
例:
mList.Insert(1,"Hei");
三、遍历List中元素:
foreach(TelementinmList)T的类型与mList声明时一样
{
Console.WriteLine(element);
}
例:
foreach(stringsinmList)
{
Console.WriteLine(s);
}
四、删除元素:
1、List. Remove(T item)删除一个值
例:
mList.Remove("Hunter");
2、List. RemoveAt(intindex);删除下标为index的元素
例:
mList.RemoveAt(0);
3、List. RemoveRange(intindex,intcount);
从下标index开始,删除count个元素
例:
mList.RemoveRange(3, 2);
五、判断某个元素是否在该List中:
List. Contains(T item)返回true或false,很实用
例:
if(mList.Contains("Hunter"))
{
Console.WriteLine("There is Hunter in the list");
}
else
{
mList.Add("Hunter");
Console.WriteLine("Add Hunter successfully.");
}
六、给List里面元素排序:
List. Sort ()默认是元素第一个字母按升序
例:
mList.Sort();
七、给List里面元素顺序反转:
List. Reverse ()可以不List. Sort ()配合使用,达到想要的效果
例:
mList.Sort();
八、List清空:
List. Clear ()
例:
mList.Clear();
九、获得List中元素数目:
List. Count ()返回int值
例:
in tcount = mList.Count();
Console.WriteLine("The num of elements in the list: "+count);
全部回答
- 1楼网友:青春如此荒謬
- 2021-02-09 12:59
手动写就类似下面的 aa bb 可用于数据绑定 datasource为数据源 datatextfield为显示数据 datavaluefield为后台数据
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯