0

Can anyone explain step by step why the result is 15?

Im a bit confused with this code. No matter how i approach it i still dont get why the result is 15. I must be missing something but im not quite sure what. class Class { public int x = 12; public int X { get { return ++x; } set { x = ++value; } } } static void Main(string[] args) { Class c = new Class(); c.X = c.X; Console.WriteLine(c.X); }

9th Jan 2020, 6:33 PM
Giura Emanuel
Giura Emanuel - avatar
3 Antworten
+ 8
creating object -> x = 12 c.X = c.X calls setter and getter -> x = 14 console.WriteLine(c.X) calls getter -> x = 15
9th Jan 2020, 6:49 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Giura Emanuel Your welcome :)
9th Jan 2020, 7:01 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Oh I get it now. Thank you very much! 😊
9th Jan 2020, 7:00 PM
Giura Emanuel
Giura Emanuel - avatar