- Back to Home »
- C#.NET »
- C#.NET If
Posted by :
Sudhir Chekuri
Thursday, 31 December 2015
If statement allows you to test whether a specific condition is met.
Syntax
if(condition)
{
//statements
}
Example program using if condition
Program
Output
Enter number
12
Positive
Output
Enter number
-5
_
Explanation
In the above output we can give input is -5.here -5 is less than zero.so nothing will be printed in output. Blank will be printed in output.
Syntax
if(condition)
{
//statements
}
Example program using if condition
Program
using System;
namespace branching
{
class Program
{
static void Main(string[] args)
{
int i;
Console.WriteLine("Enter number");
i = Convert.ToInt32(Console.ReadLine());
if (i > 0)
{
Console.WriteLine("Positive");
}
Console.ReadKey();
}
}
}
Output
Enter number
12
Positive
Output
Enter number
-5
_
Explanation
In the above output we can give input is -5.here -5 is less than zero.so nothing will be printed in output. Blank will be printed in output.