M
Mugunth
Can anyone de-mystify this?
I wrote a C# program, the entire code is shown below.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a = 0;
a = a++;
Console.WriteLine(a.ToString());
}
}
}
The output is 0 and not 1 as expected.
My question here is, why is C# ignoring the post increment operator
during a self-assignment?
I created a class and wrote a operator ++ function and tried the same
instead of "int". the operator overloaded function is getting called!
Alternatively if the assignment statement is changed to b = a++; the
output (value for a) is 1.
Can anyone de-mystify this?
I wrote a C# program, the entire code is shown below.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a = 0;
a = a++;
Console.WriteLine(a.ToString());
}
}
}
The output is 0 and not 1 as expected.
My question here is, why is C# ignoring the post increment operator
during a self-assignment?
I created a class and wrote a operator ++ function and tried the same
instead of "int". the operator overloaded function is getting called!
Alternatively if the assignment statement is changed to b = a++; the
output (value for a) is 1.
Can anyone de-mystify this?