1 more/less

Post your C# code snippets in here.
4 posts Page 1 of 1
Contributors
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

1 more/less
Axel
Instead of
Code: Select all
int x =0;

x +=1 
//or
x = x+1
just do
Code: Select all
x++
++ that means increase a variable with 1

Another tip to improve your code
Code: Select all
int x = 0;
x = x-1
//or 
x -=1
use
Code: Select all
x--
instead thnx mandai ;)

Increment/Decrement while displaying

Now you know that you can use x++ and x-- , you don't need to do this :
Code: Select all
x++
Messagebox.show(x)
or decrement and show( you should know what that means by now )
use
Code: Select all
Messagebox.Show(++x)
//or
Messagebox.Show(--x)

Tell me all mistakes you see or how it can be improved!
Last edited by Axel on Mon Apr 04, 2011 8:33 pm, edited 2 times in total.
http://vagex.com/?ref=25000
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: 1 more
mandai
Don't forget about x-- as well.
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: 1 more
Axel
Oh yes thanks
http://vagex.com/?ref=25000
User avatar
DreadNought
VIP - Donator
VIP - Donator
Posts: 116
Joined: Fri Jan 08, 2010 12:37 pm

Re: 1 more/less
DreadNought
Meh thought i'd add a quick example of it being used.
Code: Select all
using System;
using System.Text;

namespace Test
{
      class Program
      {
            byte x;
            static void Main(string[] Args)
            {
                  for (byte i = 0; i < 10; i++)
                  {
                        x--;
                        Console.WriteLine("The current value of x := {0}", x);
                  }
            }
      }
}
Bound and boom tech,
The Future Of Coding
4 posts Page 1 of 1
Return to “Quick Snips”