Difference between revisions of "Csharp programming syntax"
Wirecadadmin (Talk | contribs) |
Wirecadadmin (Talk | contribs) |
||
Line 9: | Line 9: | ||
C# uses the ; to terminate statements. As a result statements can have whitespace formatting characters(tabs, line feeds, carriage returns, etc.). | C# uses the ; to terminate statements. As a result statements can have whitespace formatting characters(tabs, line feeds, carriage returns, etc.). | ||
− | Example: | + | '''Example:''' |
− | + | <syntaxhighlight lang="csharp"> | |
CallSomeFunction(param1, param2, param3); | CallSomeFunction(param1, param2, param3); | ||
− | + | </syntaxhighlight> | |
− | is the same as:<br> | + | '''is the same as:'''<br> |
− | + | <syntaxhighlight lang="csharp"> | |
− | + | ||
CallSomefunction(param1, | CallSomefunction(param1, | ||
:param2, | :param2, | ||
:param3); | :param3); | ||
+ | </syntaxhighlight> | ||
− | |||
===Variable Declaration=== | ===Variable Declaration=== | ||
Line 35: | Line 35: | ||
Value Type Example: | Value Type Example: | ||
− | + | <syntaxhighlight lang="csharp"> | |
private int myInt = 0; | private int myInt = 0; | ||
+ | </syntaxhighlight> | ||
Reference Type Example: | Reference Type Example: | ||
+ | <syntaxhighlight lang="csharp"> | ||
private string myNewString = "fred"; | private string myNewString = "fred"; | ||
string myNewString = null; | string myNewString = null; | ||
− | + | SomeObject myObject = new SomeObject(Param1); | |
+ | SomeObject myOtherObject = null; | ||
+ | </syntaxhighlight> | ||
===Operators=== | ===Operators=== | ||
Line 62: | Line 66: | ||
if(a == a)<br> | if(a == a)<br> | ||
{ | { | ||
− | do something;<br> | + | //do something;<br> |
...<br> | ...<br> | ||
} | } | ||
else<br> | else<br> | ||
{ | { | ||
− | do something else;<br> | + | //do something else;<br> |
...<br> | ...<br> | ||
} | } | ||
− | + | ||
//simplified | //simplified | ||
if(1==1) | if(1==1) |
Revision as of 19:24, 23 December 2010
What follows is a basic look at the C# programming language.
C# is a strongly typed language. That means that the variable type matters. You cannot assign a variable of one type to another of a different type without performing a type cast. C# is compiled into IL code that is then compiled just in time by the .NET framework. The .NET framework handles things like program execution and memory management. As a result C# is considered "managed code." C# is case sensitive so Var1 is different from var1.
Contents
Basic Syntax
White Space and Comments
C# uses the ; to terminate statements. As a result statements can have whitespace formatting characters(tabs, line feeds, carriage returns, etc.).
Example:
CallSomeFunction(param1, param2, param3);
is the same as:
CallSomefunction(param1, :param2, :param3);
Variable Declaration
//value types can be initialized upon instantiation
[scope] Type name = value;
//reference types can be initialized up instantiation
[scope] Type name = new Type(contructor params);
//or not
[scope] Type name = null;
Value Type Example:
private int myInt = 0;
Reference Type Example:
private string myNewString = "fred"; string myNewString = null; SomeObject myObject = new SomeObject(Param1); SomeObject myOtherObject = null;
Operators
Assignment Operator: =
Equality Operator: ==
OR Operator: ||
AND Operator: &&
Addition: +
Subtraction: -
Multiplication: *
Division: /
Add to existing: += example: x += y is equivalent to x = x + y
Subtract from existing: -= example: x -= y is equivalent to x = x - y
Conditional Execution
//the if statement<br> if(a == a)<br> { //do something;<br> ...<br> } else<br> { //do something else;<br> ...<br> } //simplified if(1==1) SingalStatementToExecute; else SomethingElse;