Phemmy Google Search

Saturday, August 2, 2008

Basic C# Syntax

C# code is similar to that of C++ and Java. Initially the syntax can look quite confusing and is lot less like written English than some other languages. C# compilers take no notice of additional spacing in code, whether made up spaces, carriage returns or tab characters. Meaning that one have a lot of freedom in the way that on will format code; though conforming to certain rules which can make the codes easier to read.

C# code is made up of a series of statements, each of which is terminated with semicolon(;), so you don't have multiple statements on one line, but for readability's sake it is usual to add carriage return after semicolons.

C# is a block-structured language, meaning that all statements are part of a block of code. These blocks, which are represented with curly brackets({ & }), may contain any number of statements or none at all. it should noted that the curly bracket does not require semicolons.

Example 1
code line1, statement1;
code line2, statement2;
code line3, statement3;

Another important thing often seen in C# code is comments. Comments are descriptive text to your codes in plain Language(English), which is ignored by the compiler.
The first method of signifying comment is using this symbol (*/)

Example 2

/* This is a comment*/
The second method is using //, with this approach you can write whatever you like provided you keep to one line!

Example 3
//This is a different sort of comment.

The next example show case how to comment can be used on the same line with a code;

Statement; // explanation of statement.

It is pertinent to not that C# code is case sensitive. Unlike some other languages as code must be entered using the right case because using wrong case will prevent a project from compiling.


No comments: