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); }
3 Answers
+ 8
creating object -> x = 12
c.X = c.X calls setter and getter
-> x = 14
console.WriteLine(c.X) calls getter
-> x = 15
+ 2
Giura Emanuel Your welcome :)
+ 1
Oh I get it now. Thank you very much! đ