K
kelmen
Try the below simple program.
It give expected result.
1
1
2
2
Then toggle the statements in private static int sinc(), to use
Test._num ++ .
The result:
0
0
1
1
is this result acceptable? Its not expected by me.
static void Main(string[] args)
{
Test obj1 = new Test();
Console.WriteLine("obj1.Inc(): {0}", obj1.Inc());
Console.WriteLine("obj1.Num: {0}", obj1.Num);
Test obj2 = new Test();
Console.WriteLine("obj2.Inc(): {0}", obj2.Inc());
Console.WriteLine("obj2.Num: {0}", obj2.Num);
}
public class Test
{
public int Num = 0;
private static int _num = 0;
public int Inc()
{
this.Num = Test.sinc();
return this.Num;
}
private static int sinc()
{ // toggle below statements
//return Test._num ++;
return ++ Test._num;
}
}
It give expected result.
1
1
2
2
Then toggle the statements in private static int sinc(), to use
Test._num ++ .
The result:
0
0
1
1
is this result acceptable? Its not expected by me.
static void Main(string[] args)
{
Test obj1 = new Test();
Console.WriteLine("obj1.Inc(): {0}", obj1.Inc());
Console.WriteLine("obj1.Num: {0}", obj1.Num);
Test obj2 = new Test();
Console.WriteLine("obj2.Inc(): {0}", obj2.Inc());
Console.WriteLine("obj2.Num: {0}", obj2.Num);
}
public class Test
{
public int Num = 0;
private static int _num = 0;
public int Inc()
{
this.Num = Test.sinc();
return this.Num;
}
private static int sinc()
{ // toggle below statements
//return Test._num ++;
return ++ Test._num;
}
}