반응형


프로퍼티 value


키워드 value는 일반 속성 선언의 set 접근자에 사용되며, 메서드의 입력 매개 변수와 비슷합니다. 단어 value는 클라이언트 코드에서 속성에 할당하는 값을 참조합니다. 다음 예제에서 MyDerivedClass에는 Name이라는 속성이 있습니다. 이 속성은 value 매개 변수를 사용하여 지원 필드 name에 새 문자열을 할당합니다. 클라이언트 코드 측면에서 연산은 단순 할당으로 작성됩니다.

C#
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 (value != String.Empty)
            {
                name = value;
            }
            else
            {
                name = "Unknown";
            }
        }
    }

}


https://msdn.microsoft.com/library/a1khb4f8(v=vs.110).aspx

반응형

'프로그래밍(Programming) > C#' 카테고리의 다른 글

using 과 Dispose()  (0) 2017.07.19
확장메서드 public static class  (0) 2017.07.18
정적 생성자가 호출되는 시점  (0) 2015.11.14
AssemblyInfo.cs  (0) 2015.11.11
객체 배열 new , new  (0) 2015.11.11

+ Recent posts