Looking for a short & simple example of getters/setters in C#

后端 未结 12 488
悲哀的现实
悲哀的现实 2020-12-07 12:35

I am having trouble understanding the concept of getters and setters in the C# language. In languages like Objective-C, they seem an integral part of the system, bu

12条回答
  •  孤街浪徒
    2020-12-07 12:55

    This would be a get/set in C# using the smallest amount of code possible. You get auto-implemented properties in C# 3.0+.

    public class Contact
    {
       public string Name { get; set; }
    }
    

提交回复
热议问题