0

Why do public string Name {get; set;}?

class Person { public string Name { get; set; } public Person() { Console.WriteLine(name); } } static void Main(string[] args) { Person p = new Person(); p.Name = "Bob"; Console.WriteLine(p.Name); } // Yea why do that? it is exactly same as writing public steing Name; i think. Because if I want to print that " name" the compiler gives me error that "name" does not exist in current context.

14th Dec 2018, 3:16 PM
jeps997
6 ответов
0
What langauge is this?
14th Dec 2018, 3:27 PM
Vanessa Nilsson
0
Its C# Skrub jeps997 That's encapsulation, mostly used when we require to process the variable before assign or return the variable.
14th Dec 2018, 3:49 PM
Taste
Taste - avatar
0
But what Programming(s) is this?
14th Dec 2018, 3:50 PM
Vanessa Nilsson
0
langauge?
14th Dec 2018, 3:50 PM
Vanessa Nilsson
0
C#
14th Dec 2018, 4:00 PM
Taste
Taste - avatar
0
Ah sorry cant help
14th Dec 2018, 6:13 PM
Vanessa Nilsson