IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesC#Statements  Print This     

Cross Ref > Statements

By Mike Prestwood

C# versus JavaScript: A side by side comparison between C# and JavaScript.

 
Statements
 

Common statements such as if statements, loops, etc.

Exception Trapping

[Other Languages] 

Languages Focus

A common usage of exception handling is to obtain and use resources in a "try-it" block, deal with any exceptions in an "exceptions" block, and release the resources in some kind of "final" block which executes whether or not any exceptions are trapped.

C#:   try...catch...finally

C# uses a try...catch...finally statement to trap for errors.

try {}
catch {}
finally {}
Syntax Example:
try
{
int y = 0;
y = 1 / y;
}
catch
{
MessageBox.Show("you cannot divide by zero");
}
JavaScript:   try/catch/finally

See "throw" to raise (throw) an error.

Syntax Example:
try {
  //Do something.
}
catch(e) {        //one or more.
  //Do something.
}
finally {         //0 or one.
  //Do something.
}




If Statement

[Other Languages] 
C#:   if..else if..else

Use () around evaluation with no "then".

Syntax Example:
Boolean x = true;


if (x)
{
MessageBox.Show("hello");
}
else if (x==false)
{
MessageBox.Show("goodbye");
}
else
{
  MessageBox.Show("what?");
}
JavaScript:   if..else if..else

Same as C/C++ but, as usual, the semicolons are optional.

Syntax Example:
var x = 8;
  
if (x == 10) {
 document.write("x is 10.");
} else if (x < 10) {
 document.write("x is less than 10."); 
} else {
 document.write("x must be greater than 10.");
}




Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2025 Prestwood IT Solutions.   [Security & Privacy]