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#  Print This     

If Statement (C# and Delphi Cross Reference Guide)

By Mike Prestwood

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

 
Statements
 

Common statements such as if statements, loops, etc.

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?");
}
Delphi:   If..Else If..Else

Notice in the more complete example that the semicolon for the begin..end block after end is not included. That tells the compiler something else is coming (the statement is not finished). Also note the semicolon is missing right before the final "else" statement.

Note: The following example uses floating point literals. In Delphi, to specify a fractional floating point literal between 1 and -1, you preceed the decimal with a 0; otherwise, you will get a compiler error (i.e. .1 + .1 does not work).

Syntax Example:
if (0.1 + 0.1 + 0.1) = 0.3 then
  ShowMessage('Correct')
else
  ShowMessage('Not correct');
 
//Complete example:
if x = true then
begin
  ShowMessage('x is true');
end
Else If y = 'Mike' Then 
  ShowMessage('hello mike')
Else 
  ShowMessage('last option');












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


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