Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 添加到列表时出错_Asp.net - Fatal编程技术网

Asp.net 添加到列表时出错

Asp.net 添加到列表时出错,asp.net,Asp.net,我在向列表添加对象时遇到问题。我正在使用.NETFramework2.0 用于创建对象并将其添加到列表的代码 List<GetInvalidElement> objInvaliElement = new List<GetInvalidElement>(); objInvaliElement.Add(new GetInvalidElement() {ElementType="Accomodation",ElementId=intACC,ElementInvalidReaso

我在向列表添加对象时遇到问题。我正在使用.NETFramework2.0

用于创建对象并将其添加到列表的代码

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; }
        }
    }