Is getting / installing in C # easier?

Hey, that's why I'm currently writing a program for the university, and when I create my classes I use get set my question is is there an easier way than this method shown below to install something.

Code snippet showing my current way

private string customer_first_name; private string customer_surname; private string customer_address; public DateTime arrival_time; //Using accessors to get the private variables //Using accessors to set the private variables public string Customer_First_Name { get { return customer_first_name; } set { customer_first_name = value; } } 
+4
source share
3 answers

Use automatically implemented properties :

 public string Customer_First_Name { get; set; } 

In this case, the compiler will generate a field to store the property value.

By the way, you can save even more time if you use the prop code snippet in Visual Studio. Just start typing prop and press Tab - it inserts a snippet for an automatically generated property. All you need to do is specify the name and type of the property.

+9
source
 public string Customer_First_Name { get; set; } 

enough if you don't need any logic in your getter / setter.

+1
source
 public string Customer_First_Name {get; set;} 

Doing this also implicitly creates a base field for you.

0
source

Source: https://habr.com/ru/post/1446771/


All Articles