C#を勉強というかUnityを勉強していたらプロパティというものがあることを知りました。
ということで忘れないために備忘録。
コード
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class A
{
int b;
public int B
{
set { b = value; }
get { return b; }
}
public A()
{
b = 10;
}
}
class Program
{
static void Main(string[] args)
{
A a = new A();
Console.WriteLine(a.B);
a.B = 20;
Console.WriteLine(a.B);
}
}