Рубрики
Fragments "Unity-C#" C# test "C#" Метод ООП "Интерфейс"

C# «Метод интерфейса присваивает значения свойствам без реализации в классе»

using UnityEngine;
namespace test2208041738
{
    public interface ITest
    {
        public byte Prop1
        {
            get;
            set;
        }
        public string Prop2
        {
            get;
            set;
        }
public void Method_props_assign() => this.Method(2, "hello");

public (byte, string) Method(byte Prop1, string Prop2) => (this.Prop1 = Prop1, this.Prop2 = Prop2);
}
    public class Test : ITest
    {
        private byte _prop1;
        private string _prop2;
        
        public byte Prop1
        {
            get => _prop1;
            set => _prop1 = value;
        }
        public string Prop2
        {
            get => _prop2;
            set => _prop2 = value;
        }
        static public void test()
        {
            ITest t = new Test();
            t.Method_props_assign();
            Debug.Log(t.Prop1 + "," + t.Prop2);
        }
    }
}