M
M
milkyway12020-11-25 21:51:16
OOP
milkyway1, 2020-11-25 21:51:16

Which field creates an automatic property?

Good evening. I'm learning OOP in C#, but I don't understand one point. When we manually define properties, there is a field and corresponding get and set accessors , but when declaring automatic properties

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

it is not clear under what name the compiler creates a field for Name.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
milkyway1, 2020-11-25
@milkyway1

As I understand it, the compiler creates a field and a property with the same name, and if I want to expand the Name accessors to write logic, I will have to declare the name field in the class and perform operations on it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question