Jitesh Byahut 8/28/2015 2585

C# Introduction

C# is powerful object oriented and type-safe programming language. C# pronounced as "C Sharp" that developed by Microsoft. In January 1999, Mr. Anders Hejlsberg build a team to develop a new language that is called as COOL on that time, which stood as C-Like Object Oriented Language. Finally in July 2000 at Professional Developer Conference, Microsoft announced the language renamed as C#. That was inspired by musical notation "sharp".

C# is similar to C++, Java and VB. Like C++, operator overloading, enumeration, pre-processor directives, pointers, function pointer (delegates). Like VB, its supports the concepts of properties. Like Java, C# does not allow multiple inheritance. But also C# comes up with some new features such as reflections, attributes, remoting, thread, streams, Linq, dynamic and many more.


Identifier is represent a unique user defined name for variable, class, function, event or interface.

Rule of defining an identifiers:

1. Identifier can be unique name in the specific region where it's defined.

2. It can be alphanumeric name and start with underscore ( _ ) but not start with a numeric value.

3. It cannot be a keyword. If you want to use keyword as identifier the prefix "@" symbol.
    For example, public is a keyword. So you can use like @public.

4. Identifiers are case-sensitive, means "abc" and "ABC" both are different-different identifiers in C#.

5. White-space not allowed between characters of variable.


Variable is a type of object or property or field that represent a data type object and can be store a specific value. In other words, variable is holding a value and indicating that memory location.
C# is a type-safety language, so each variable is representing a specific type at compile time or run time.

In below example, we are defining a variable x that is holding integer value 10.

// <data type> <variable name>;

    int x = 10; 

// Here x is a variable that holding value of 10

There are different-different ways to declare the variable and assign the values.

// Rule of defining variable in c#:         

// Option 1

int a; 

// Option 2

int a = 10; 

// Option 3

int a, b, c; 

// Option 4

int a = 10, b, c; 

// Option 5

int a = 10, b = 20, c = 50;


Expression is combination of operands and operator. An expression is a sequence of one or more operands and zero or more operators that can be evaluated to a single value, object, method or namespace. Expression can consist of a literal value, a method invocation, an operator and its operands or a simple string value.

 // Operators and operands expression

        int a = 10;

        int b = ((a + 25) * (a - 5) * 120);


        // literal and simple name expression

        int i = 5;

        string abc = "Asphelps Tutorial";


        // Method invocation expression



Keywords are predefined reserved identifiers that have a special meaning to the compiler. They cannot be used as identifier, if you want then use @ syntax as prefix.

Types of keyword:

1. Reserved Keyword – That always have a reserved special meaning. You cannot use these keywords as identifier in you programming. For example: public, private, base, new, null, out, return, if, foreach, void, abstract, interface etc.

2. Contextual Keyword – That have special meaning only in a limited program context and that can be used as identifier outside of context. For example: get, set, var, value, from etc.


A statement can consist of a single line of code that end with semicolon, or series of single-line statements in a block. A statement can be a block of codes that enclosed in { } brackets or can be nested blocks.

Types of statement:

1. Selection statement
if, else, switch

2. Iteration statement
for, foreach, while, do-while

3. Jump statement
break, return, goto, continue

4. Exception statement
try, catch, finally, throw

Please give your feedback for improving this page