if statement without braces

If if statement only has one statement we can omit the braces{}.


using System;

class Program
{
    static void Main(string[] args)
    {
        int i = 5;
        if (i > 0)
            Console.WriteLine("more than 0");
    }
}

The output:


more than 0

The good practice is to add the braces all the time.

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.