プロパティ

get、setというアクセッサを使用することで定義された値の受け渡しが可能

サンプル

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication34
{
    class Program
    {
        static void Main(string[] args)
        {
 
            Test1 a = new Test1();
            a.kingaku = 1000;             // プロパティを使用した場合はpublicの変数のような感覚で値の受け渡しが可能
            Console.WriteLine(a.kingaku);
 
            Console.ReadKey();
 
        }
    }
 
    class Test1
    {
        // メンバ定義
        private int data;
 
        // プロパティ定義
        public int kingaku
        {
            // ゲッター
            get
            {
                return data;
            }
            //セッター
            set
            {
                this.data = value;
            }
        }
    }
}
 
 
 





最終更新:2011年04月10日 10:45