Main Menu

HOME

.Net
ASP
Assembly
C
C++
Delphi
HTML
Java
JavaScript
MySQL
PC interface
Powershell
Perl
PHP
VBScript
Visual Basic
XML

US Job listings




   Misc

   Amazon

   Links

IF statement in C#


 

if statement has the same syntax as in C, C++, and Java. Thus, it is written in the following form:

if-statement ::= "if" "(" condition ")" if-body ["else" else-body]
condition ::= boolean-expression
if-body ::= statement-or-statement-block
else-body ::= statement-or-statement-block

The if statement evaluates its condition expression to determine whether to execute the if-body. Optionally, an else clause can immediately follow the if body, providing code to execute when the condition is false. Making the else-body another if statement creates the common cascade of if, else if, else if, else if, else statements:

using System;
public
class IfStatementSample
{
public void IfMyNumberIs()
{
int myNumber = 5;
if ( myNumber == 4 )
Console.WriteLine("This will not be shown because myNumber is not 4.");
else
if( myNumber < 0 )
{
Console.WriteLine("This will not be shown because myNumber is not negative.");
}
else
if( myNumber % 2 == 0 )
Console.WriteLine("This will not be shown because myNumber is not even.");
else

{
Console.WriteLine("myNumber does not match the coded conditions, so this sentence will be shown!");
}
}
}

 

All text is available under the terms of the GNU Free Documentation License
Source : Wikibooks

 

 

 



 




   Sponsors
 

   Software
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals

   Source Code
Delete a file(C)
random white dots(Darkbasic)
disable CTRL + ALT + DEL on Windows XP(VB)
Blinking label(VB)
load a bitmap(Blitzbasic)
Octal, hex and decimal(C++)
display serial port configuration(VBScript)
Display all sub-folders of a given path(VBNet)




Copyright © 2004 by programmershelp.co.uk