SampleScript.cs
using UnityEngine;
namespace Assets.Samples.Sample4
{
public class SampleScript : MonoBehaviour
{
private readonly Person _field = new Person();
private Person _property => new Person();
private void Start()
{
_field.Init("Mike", 25);
_property.Init("Lucas", 35);
_field.Introduce();
_property.Introduce();
}
}
}
Person.cs
using UnityEngine;
namespace Assets.Samples.Sample4
{
public class Person
{
public string Name { get; private set; } = "John";
public int Age { get; private set; } = 18;
public void Init(string name, int age)
{
Name = name;
Age = age;
}
public void Introduce()
{
Debug.Log(quot;Hey, I'm {Name}, {Age} yo.");
}
}
}
6 comments