关于List的疑惑!
admin 发表于 2010-08-28 | 来源:互联网 | 阅读:
struct CValue
{
public int IDNumber;
public int Value;
public int HalfValue;
}
声明一个结构体
ContoursValue temp;
List<CValue> CV = new List<ContoursValue>();
temp.IDNumber = 0;
temp.HalfValue = http://topic.csdn.net/u/20100827/08/0;
temp.Value = http://topic.csdn.net/u/20100827/08/0;
CV.Add(temp);
我发现 如果不给这个结构体 都赋值的话 是无法加进链表里的 ,请问有什么其他的方法?
因为我想减少内存读入的数据量! 所以链表中 有些项不想全部赋值!

struct CValue { public int IDNumber=0; public int Value =http://topic.csdn.net/u/20100827/08/0; public int HalfValue =http://topic.csdn.net/u/20100827/08/0; }设置默认值
太有速度了。。。
struct CValue { public int IDNumber=0; public int Value =http://topic.csdn.net/u/20100827/08/0; public int HalfValue =http://topic.csdn.net/u/20100827/08/0; }设置默认值恩 我也想过设置默认值,我发贴的目的 是征求更多更好的意见,最近变的很不自信!
没有值是不允许使用的。
没有值是不允许使用的。是啊!!!!!有什么好的方法没 除了给不要的地方赋值0
struct CValue { public int IDNumber; public int Value; public int HalfValue; }声明一个结构体 ContoursValue temp; List<CValue> CV = new List<ContoursValue>(); temp.IDNumber = 0; t……C#的数据,在使用之前都必须初始化过。
定义为int?试试
用默认值不好么?
ContoursValue temp = new ContoursValue(); List<CValue> CV = new List<ContoursValue>(); temp.IDNumber = 0; temp.HalfValue = http://topic.csdn.net/u/20100827/08/0; temp.Value = http://topic.csdn.net/u/20100827/08/0; CV.Add(temp);
//New即可ContoursValue temp = new ContoursValue();List<CValue> CV = new List<ContoursValue>();CV.Add(temp);
请问下 List 使用后要不要释放?我很担心这个很消耗内存!是不是能使用普通的数组 尽量不要使用这种LIST?
设置可空类型Nullable
不赋值,但是也得需要new了吧。ContoursValue temp; List<CValue> CV = new List<ContoursValue>(); temp.IDNumber = 0; temp.HalfValue = http://topic.csdn.net/u/20100827/08/0; temp.Value = http://topic.csdn.net/u/20100827/08/0; CV.Add(temp);难道不会出现”未将对象引用到对象实例“吗?
New即可
ContoursValue temp = new ContoursValue(); List<CValue> CV = new List<ContoursValue>(); CV.Add(temp);这样不可以?
恩 谢谢!!!!
学习了