Asp.net 添加到列表时出错
我在向列表添加对象时遇到问题。我正在使用.NETFramework2.0 用于创建对象并将其添加到列表的代码Asp.net 添加到列表时出错,asp.net,Asp.net,我在向列表添加对象时遇到问题。我正在使用.NETFramework2.0 用于创建对象并将其添加到列表的代码 List<GetInvalidElement> objInvaliElement = new List<GetInvalidElement>(); objInvaliElement.Add(new GetInvalidElement() {ElementType="Accomodation",ElementId=intACC,ElementInvalidReaso
List<GetInvalidElement> objInvaliElement = new List<GetInvalidElement>();
objInvaliElement.Add(new GetInvalidElement() {ElementType="Accomodation",ElementId=intACC,ElementInvalidReason=strErrorMessage});
在2.0中不能使用匿名构造函数,它是在3.0中引入的。您必须创建实例,并通过实例将值分配给属性
public class GetInvalidElement
{
private string _elementType;
private int _elementId;
private string _elementInvalidReason;
public string ElementType
{
get { return _elementType; }
set { _elementType = value; }
}
public int ElementId
{
get { return _elementId; }
set { _elementId = value; }
}
public string ElementInvalidReason
{
get { return _elementInvalidReason; }
set { _elementInvalidReason = value; }
}
}