List怎么用? C#中应该也有List吧,怎么用啊?谁能给出示例代码?我用数组表示自己建的类,发现不能用下标来赋值啊. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 list很好用,可以把对象add进去. C#中有List<T>泛型,引用System.Collection.General命名空间。 using System;using System.Collections.Generic;class GenericListDemo{ static void Main(string[] args) { List<int> alInt32 = new List<int>(); foreach (int number in new int[] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }) { alInt32.Add(number); } OutputMethod(alInt32); List<double> alDouble = new List<double>(); foreach (double number in new double[] { 10.1, 9.2, 8.3, 7.4, 6.5, 5.6, 4.7, 3.8, 2.9, 1.1 }) { alDouble.Add(number); } OutputMethod(alDouble); } private static void OutputMethod<T>(List<T> al) { foreach (T temp in al) { Console.Write(temp + " "); } Console.WriteLine(); } } IList<可序列化的类> list=new List<可序列化的类>(); List <类名称> list=new List <同一个类>();类 Emp = new 类();list.Add(Emp); List<数据类型> str=new List<数据类型>str.add(数据1);str.add(数据2); 大家都说的差不多了呵呵,这就是个动态数组,定义和使用都相当方便List <数据类型> str=new List <数据类型> 取值的时候和数组的取值一样,第一个就str[0],用起来比数组要好的多嘿嘿不过里面的类型必须是统一的(实际操作中大部分都是同一类型数据)而哈希表它的数据比这个复杂了就,但用起来不如找个爽呵呵 我觉得这个跟ArrayList差不多吧 C#调用Oracle里的函数,返回一个结果集。。求代码 请大家帮忙写一个正则表达式,谢谢大家啦。 简写if语句有没有性能和效率上的损失? C#与硬件通信 谁能帮个忙啊 对话框浮于主窗体之上,就象记事本的“查找”对话框一样,怎么做呢? 我要用C#做出来这样的东西..不知道理论上可行否.. FileSystemWatcher怎么动态创建和监测多个文件夹 请教Datagrid控件问题? 请问谁知道哪里有C#高级编程(清华大学出的)下载??????? 我想问下怎么实现窗体的滑动关闭 数据结构(C#版本)
using System.Collections.Generic;class GenericListDemo
{
static void Main(string[] args)
{
List<int> alInt32 = new List<int>(); foreach (int number in new int[] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 })
{
alInt32.Add(number);
}
OutputMethod(alInt32); List<double> alDouble = new List<double>(); foreach (double number in new double[] { 10.1, 9.2, 8.3, 7.4, 6.5, 5.6, 4.7, 3.8, 2.9, 1.1 })
{
alDouble.Add(number);
}
OutputMethod(alDouble);
} private static void OutputMethod<T>(List<T> al)
{
foreach (T temp in al)
{
Console.Write(temp + " ");
}
Console.WriteLine();
}
}
str.add(数据2);
取值的时候和数组的取值一样,第一个就str[0],用起来比数组要好的多嘿嘿
不过里面的类型必须是统一的(实际操作中大部分都是同一类型数据)而哈希表它的数据比这个复杂了就,但用起来不如找个爽呵呵