Search code examples
c#increment

count++ and ++count, when to use which?


So i came across this little incrementing method

since highschool and univeristy I am used to this kind of method

char[] NewArray = new char[5] //I forgot how to declare an array

string temp;

console.writeline("Enter 5 letters)

for (i=0; i<5;i++)
{
   NewArray[i] = console.readline()
}

now based on this code

I declare an array of char with 5 "spaces", then I ouput a message to the console asking the user to enter 5 values

so i = 0, readline e.g. c

thus BEFORE the console.readline statment, i=0, then it continues through the for loop, then returns to the beginning of the loop, incrementing i = 1 BEFORE excecuting the console.readline again

how does this differ to "++i", what will the "++i" do in the for loop?


Solution

  • count++ is post increment where ++count is pre increment. suppose you write count++ means value increase after execute this statement. but in case ++count value will increase while executing this line.