0

what do get {} and set {} do in c#

during a code coach i saw get {} and set {} in the code and didnt know what they meant. heres the code coach: https://sololearn.com/coach/688/?ref=app

22nd Jul 2022, 11:41 AM
bwv822 🇨🇦
bwv822 🇨🇦 - avatar
2 Respostas
0
A Code for that would be: private int age; public int Age{get; set;} What you search for's named properties and comes in the c# course Part with courses. You can see that as Kind of middle man in giving values to variables, let's say we have two classes Dog and Main: class Dog { private int age; public int Age{get; set;} } class Main { Dog d = new Dog(); Dog.age= 5; //The age variable isn't accessable because it's Set on private. Dog.Age = 5; //The property now have the use to declare the variable } It's also possible to write Age{get;} with that you make the variable not declarable outside of the class and readonly. For further Infos can you Look Up properties or go further in the c# course. 😉 edit: Properties's Lesson 39.1 from the c# courses.
22nd Jul 2022, 12:16 PM
Felix Alcor
Felix Alcor - avatar
0
i understand now thank you
22nd Jul 2022, 7:27 PM
bwv822 🇨🇦
bwv822 🇨🇦 - avatar