Monday, July 27, 2009

Basics of C#...!

Classes are the blue-prints, who defines behavior of the type or custom elements. These can be defined as Public or Private and supports the Inheritance OOPs characteristic. Classes can also be defined as static.
Structs are mostly same as classes, although these are more limited than classes. Within a struct declaration, fields cannot be initialized unless they are declared as const or static. A struct may not declare a default constructor or destructor. It can not be inherited from another struct or class. All structs inherit directly from System.ValueType.
Namespace helps to control the scope of class and method names in larger programming projects.
Interface describes a group of related functionalities that can be belongs to any class or struct. It may consists of methods, properties, events, indexers. The interface itself does not provide any functionality. Its provides an implementation framework for the class or struct. Interfaces are always public.
Delegates are types that define a method signature, and can be associated with any method. We can invoke a method through the delegate. Delegates are used to pass methods as arguments to other methods.
Indexers allow instances of a class or struct to be indexed just like arrays. Indexers resemble properties except that their accessors take parameters.
Enumeration type provides an efficient way to define a set of named integral constants that may be assigned to a variable. For example, assume that you have to define a variable whose value will represent from a specific predefined list.
Enumerationcan be defined using the enum keyword.

Data Types
Character(char) is not a true integral data type in C#, but we can use this data type to specify single character. This has been derived from System.Char.
String data type is used to store string values.
Integer Like other programming languages, this data type is used to store numeric data. In C# integer come with the range of 8 bit (short) to 64 bit (long) wide.
TypeNameSpace Description
sbyte System.SByteSigned 8 bit
byteSystem.Byte Unsigned 8 Bit
shortSystem.Int16Signed 16 Bit
ushort System.uInt16UnSigned 16 Bit
intSystem.Int32Signed 32 Bitn
uintSystem.uInt32UnSigned 32 Bitn
longSystem.Int64Signed 64 Bit
ulongSystem.uInt64UnSigned 64 Bit
Floating point data type is used to store floating or decimal numeric data. in C# floating points come with the Single (float), double and decimal.
TypeNameSpaceDescription
floatSystem.SingleRange from -3.402823*10e38 to -3.402823*10e-38
doubleSystem.DoubleRange from -1.79769313486232*10e38 to 1.79769313486232*10e38
decimalSystem.DecimalRange from -3.402823 * 10e38 to -3.402823 * 10e-38
Boolean (bool) data type is used to store two possible values like true or false. This data type has been derived from System.Boolean.

Operator and Precedence
CategoryOperators
Primary(x) x.y f(x) a[x] x++ x-- new typeof sizeof checked unchecked
Unary + - ! ~ ++x --x (T)x
Multiplicative* / %
Additive+ -
Relational< > <= >= is as
Equality== !=
LogicalAND(&) XOR(^) OR () Conditional AND (&&) Conditional OR ()
Assignment= *= /= %= += -= <<= >>= &= ^= =

Selection or BranchingC# support the same selection or Branching statement as other programming languages. Like if-- else, switch -- case -- default.
if -- else is the basic selection statement and commonly used in C# for the branching with the Boolean expressions. Like other programming languages if--else statement can be nested and their can be multiple condition with the help of the logical operators.
if (intRowNumber == 5)
{ intColNumber++;}
else
{
intColNumber -= 1;
}
Switch -- Case -- Default is the most commonly used, when we have the multiple choices based on the condition.
switch (intRowNumber)
{
case 0: intColNumber = -1;
break;
default: intColNumber = -9999;}

Iteration Statements support the code to be executed in the loop or multiple times until the condition satisfied the purpose. Like other C# supports while, Do--While, for and foreach looping.

No comments:

Post a Comment