Difference between revisions of "Csharp programming syntax"
Wirecadadmin (Talk | contribs) |
Wirecadadmin (Talk | contribs) |
||
Line 1: | Line 1: | ||
+ | '''What follows is a basic look at the C# programming language.<br>''' | ||
+ | |||
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. | 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. | ||
Line 21: | Line 23: | ||
===Variable Declaration=== | ===Variable Declaration=== | ||
− | //value types can be initialized upon instantiation | + | //value types can be initialized upon instantiation<br> |
[scope] Type name = value; | [scope] Type name = value; | ||
− | //reference types can be initialized up instantiation | + | //reference types can be initialized up instantiation<br> |
[scope] Type name = new Type(contructor params); | [scope] Type name = new Type(contructor params); | ||
− | //or not | + | //or not<br> |
[scope] Type name = null; | [scope] Type name = null; | ||
Line 42: | Line 44: | ||
===Operators=== | ===Operators=== | ||
+ | Assignment Operator: = | ||
+ | Equality Operator: == | ||
+ | OR Operator: || | ||
+ | AND Operator: && | ||
+ | Addition: + | ||
+ | Subtraction: - | ||
+ | Multiplication: * | ||
+ | Division: / | ||
+ | Add to existing: += | ||
+ | Subtract from existing: -= |
Revision as of 03:44, 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.
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:
//This is a comment and will not execute CallSomeFunction(param1, param2, param3);
is the same as:
//This is a comment and will not execute 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;
Operators
Assignment Operator: = Equality Operator: == OR Operator: || AND Operator: && Addition: + Subtraction: - Multiplication: * Division: / Add to existing: += Subtract from existing: -=