在使用list<T>时,添加值之前必须在构造函数里面讲对象实例化例如private List<TResult> trans_result;
public List<TResult> Trans_result
{
get
{
if (trans_result == null)
trans_result = new List<TResult>();
return trans_result;
}
set { trans_result = value; }
}
}
class TResult
{
public string src { get; set; }
public string dst { get; set; }
}
public List<TResult> Trans_result
{
get
{
if (trans_result == null)
trans_result = new List<TResult>();
return trans_result;
}
set { trans_result = value; }
}
}
class TResult
{
public string src { get; set; }
public string dst { get; set; }
}
本文详细解释了在使用泛型类时如何在构造函数中实例化对象,并通过属性进行获取和设置操作,包括如何处理初始值为空的情况。

被折叠的 条评论
为什么被折叠?



