I am new to C# programming. Please help me.
I created a class Tester
:
class Tester
{
public int a = 5;
public int b = a;
}
Question 1 : Why am I not able to use this variable a
for initializing the variable b
.
Question 2: If I changed the variables to static then it works fine. Why is there a difference?
class Tester
{
public static int a = 5;
public static int b = a;
}
Question 3 : In previous example if I swap the sequence of variable then it works fine why because a
is declaring after b
. How can it initialize a
?
class Tester
{
public static int b = a; // 0
public static int a = 5; // 5
}