c#数组与泛型列表 [英] c# array vs generic list
本文介绍了c#数组与泛型列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我基本上想知道在下面提到的场景中使用通用列表而不是数组的区别或优势
i basically want to know the differences or advantages in using a generic list instead of an array in the below mentioned scenario
class Employee
{
private string _empName;
public string EmpName
{
get{ return _empName; }
set{ _empName = value; }
}
}
<小时>
1. Employee[] emp
2. List<Employee> emp
谁能告诉我优点或缺点以及更喜欢哪一个?
can anyone please tell me the advantages or disadvantages and which one to prefer?
推荐答案
一个很大的区别是 List
可以扩展(可以调用 Add 就可以了)也可以收缩(可以调用删除它)而 Employee[] 的大小是固定的.因此,除非需要,Employee[]
很难使用.
One big difference is that List<Employee>
can be expanded (you can call Add on it) or contracted (you can call Remove on it) whereas Employee[] is fixed in size. Thus, Employee[]
is tougher to work with unless the need calls for it.
这篇关于c#数组与泛型列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文