C# 泛型和数组在 C# 2.0 中,下限为零的一维数组自动实现 IList
成都创新互联成立于2013年,先为卢龙等服务建站,卢龙等地企业,进行企业商务咨询服务。为卢龙企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
C# 泛型和数组代码
- class Program
- {
- static void Main()
- {
- int[] arr = { 0, 1, 2, 3, 4 };
- List
list = new List (); - for (int x = 5; x < 10; x++)
- {
- list.Add(x);
- }
- ProcessItems
(arr); - ProcessItems
(list); - }
- static void ProcessItems
(IList coll) - {
- foreach (T item in coll)
- {
- System.Console.Write(item.ToString() + " ");
- }
- System.Console.WriteLine();
- }
- }
C# 泛型和数组应用时注意
尽管 ProcessItems 方法无法添加或移除项,但对于 ProcessItems 内部的 T[],IsReadOnly 属性返回 False,因为该数组本身未声明 ReadOnly 特性。
C# 泛型和数组的相关内容就向你介绍到这里,希望对你了解和学习C# 泛型和数组有所帮助。