Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this mean ? public Name {get; set;} [duplicate]

Tags:

c#

properties

I see this quiet often in C# documentation. But what does it do?

public class Car {    public Name { get; set; } } 
like image 750
naim5am Avatar asked Aug 21 '09 05:08

naim5am


People also ask

What does get set do?

Example explained The get method returns the value of the variable name . The set method assigns a value to the name variable. The value keyword represents the value we assign to the property.

What is the use of Get and Set in C#?

A get property accessor is used to return the property value, and a set property accessor is used to assign a new value.

What does get mean C#?

The get keyword defines an accessor method in a property or indexer that returns the property value or the indexer element. For more information, see Properties, Auto-Implemented Properties and Indexers.


1 Answers

It is shorthand for:

private string _name;  public string Name {     get { return _name; }     set { _name = value; } } 

The compiler generates the member variable. This is called an automatic property.

like image 134
Bryan Watts Avatar answered Oct 17 '22 23:10

Bryan Watts