0
my x1 value is not available
namespace revisoes { class Correct { private double x1, x2; static void Main() { Correct x1 = new Correct(); x1 = 100; Console.WriteLine(x1); } } }
5 Réponses
+ 11
@Ipang No sorry! It's because the program entry point (main) is within the same class as the instance variable.
It wouldn't work if the variable is from another class. 😉
+ 10
You got 2 definitions of x1 here, one for a double-precision value and one for the class object itself.
Perhaps you can fix it by following:-
Correct obj = new Correct();
obj.x1 = 100;
Console.WriteLine(obj.x1);
+ 9
@Zephyr ooh I see now : )
Thank you for the explanation, learned a new thing from this, will make a note on that : )
+ 8
@Ipang You're welcome! 😄
+ 7
@Zephyr, I am sorry, I don't really understand why the private x1 here is accessible to be exposed through an instance as if it were public?