문제

public List<ObjectA> ObjectAList
{
    get
    {
        return ObjectAList ?? new List<ObjectA>();
    }

    set;
}

'ObjectAList.set' must declare a body because it is not marked abstract, extern, or partial

Why is that?

도움이 되었습니까?

해결책

You are trying to mix Auto implemented property with normal property. Moreover you need a backing field, otherwise you will run in to Stackoverflow exception. Your property declaration should be like:

private List<ObjectA> _ObjectAList; //private backing field
public List<ObjectA> ObjectAList
{
    get
    {
        return _ObjectAList ?? new List<ObjectA>();
    }

    set
    {
        _ObjectAList = value;
    }
}

다른 팁

Thats how the langauge works.

You cant do partial explicit / implicit.

Its all or nothing.

When you do it implicitly it just writes to an auto generated backing field, but it wants to do both sides. Moreover your get is going to have a stack overflow even if the set worked because you are going to call the get over and over with no base case to end the recursion.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top