I have a simple c# console application but i am getting wrong output why?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication11
{
class Program
{
    static void Main(string[] args)
    {
        int i = 100;
        for (int n = 0; n < 100; n++)
        {
            i = i++;
        }
        Console.WriteLine(i);
    }
}
}
                i++ is an expression which returns i, then increments it.
Therefore, i = i++ will evaluate i, increment i, then assign i to the original value, before it was incremented.
You need to use ++i, which will return the incremented value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With