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     

Code Blocks (C# and Java Cross Reference Guide)

By Mike Prestwood

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

 
Language Basics
 

Language basics is kind of a catch all for absolute beginner stuff. The items (common names) I chose for language basics is a bit random and include items like case sensitivity, commenting, declaring variables, etc.

Code Blocks

[Other Languages] 

Languages Focus

The rules for code blocks within a language dictate where you can declare variables, how you "bracket" code, etc.

C#:   { }

C# uses braces {} to indicate a code block of more than one line. For one line of code, the braces are optional.

I prefer to put the opening { and the closing } on their own line only because most of the examples I see do this. As opposed to C++, Java, and JavaScript where I put the opening bracket at the end of the first line (which I actually prefer).

Syntax Example:
int DoSomething()
{
 int a = 1;
 int b = 2;
 return a + b;
}
Java:   { }

Curly braces are used to bracket code blocks including classes and the methods within a class.

For Java, JavaScript, PHP, and C++, I prefer to put the first { at the end of the first line of the code block as in the example above because I see moreJava codeformatted that way.

Syntax Example:
public class Dog {
  public bark() {
    System.out.println("Ruff");
  }
}












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


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