value(C# 참조)

상황별 키워드 value속성인덱서 선언의 set 접근자에 사용됩니다. 메서드의 입력 매개 변수와 비슷합니다. value 단어는 클라이언트 코드에서 속성 또는 인덱서에 할당하려는 값을 참조합니다. 다음 예에서 MyDerivedClass에는 Name이라는 속성이 있습니다. 이 속성은 value 매개 변수를 사용하여 지원 필드 name에 새 문자열을 할당합니다. 클라이언트 코드의 관점에서 이 작업은 단순한 할당으로 기록됩니다.

class MyBaseClass
{
    // virtual auto-implemented property. Overrides can only
    // provide specialized behavior if they implement get and set accessors.
    public virtual string Name { get; set; }

    // ordinary virtual property with backing field
    private int _num;
    public virtual int Number
    {
        get { return _num; }
        set { _num = value; }
    }
}

class MyDerivedClass : MyBaseClass
{
    private string _name;

    // Override auto-implemented property with ordinary property
    // to provide specialized accessor behavior.
    public override string Name
    {
        get
        {
            return _name;
        }
        set
        {
            if (!string.IsNullOrEmpty(value))
            {
                _name = value;
            }
            else
            {
                _name = "Unknown";
            }
        }
    }
}

자세한 내용은 속성인덱서 문서를 참조하세요.

C# 언어 사양

자세한 내용은 C# 언어 사양을 참조하세요. 언어 사양은 C# 구문 및 사용법에 대 한 신뢰할 수 있는 소스 됩니다.

참고 항목