0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【C#】【文法】プロパティ

Posted at

    // プロパティ
    class Practice8_1
    {
        
        static void Main(string[] args)
        {
            // プロパティを介してprivateな変数にアクセスできる。
            Sample s = new Sample();
            s.Param1 = 10;
            int n = s.Param1;
        }
        
    }

    class Sample
    {
        private int _param1;

        // SetterとGetterを定義する。
        public int Param1
        {
            set
            {
                this._param1 = value;
            }
            get
            {
                return this._param1;
            }
        }

        // 自動プロパティ
        public int Param2 { get; set; }
        // 読み取り専用
        public int Param3 { get; private set; }
    }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?