Getting Started with C#

Getting Started with C#











Getting Started with C#


















What is C# all about?
C# was developed at Microsoft. It is an object-oriented programming language and provides excellent features such as strong type checking, array bounds checking and automatic garbage collection. We will explore these and several other features in this article.

C# has features that make it an excellent choice for developing robust distributed n-tier Enterprise applications, web applications, windows applications and embedded systems. It is used for building applications ranging from the very large that use sophisticated operating systems, down to the very small having specialist functions

Getting Started:
Here is a very simple “Hello World” program written using C#. The code for C# program is written in text files with an extension “.cs”

Example:
1) Create a text file “First.cs” 2) Type the following code and ‘save’
using System; class myClass { static void Main()
{ Console.WriteLine("Hello World"); } }
3) From the command line compile the above code by typing the following csc First.cs 4) This creates First.exe 5) Run this exe from the command line and you see an output – Hello World
Having seen the example above we will now review the concepts and elements of the C# programming language. After that we will review the above example once again to understand what each line of code does. To get a better grasp of the C# language it is helpful if you have some programming experience and even better if you have experience in Object Oriented Programming. We now examine the C# language concepts and elements one by one.

A) OOP
C# is an object oriented Programming language and it supports the Object Oriented Programming Methodology. When creating a software solution you can represent the real world entities as “objects” of different “types”.

a. Types: C# supports mainly two kinds of types: value types and Reference types. The difference lies in the way in which handles these tow kinds of types. Examples of value types are – char, int, structures, enums . Examples of Reference types are – class, interface, delegate, arrays

i. Variables represent storage locations. Every variable is of a specific ‘type’. This determines what values can be stored in it.

ii. Field is a variable that is associated with a Class or Struct, or an instance of a class or struct.


iii. Parameters: There are four kinds of parameters: value parameters, reference parameters, output parameters, and parameter arrays.

iv. Classes: Classes are blueprints for objects. You instantiate an object from class. An object thus instantiated if said to be of a reference types. As C# is an Object Oriented Programming Language a class can inherit from another class, and can implement interfaces. Each Class can have one or members such as methods, properties, constants, fields, events, constructors, destructors and so on.

v. Structs: Structs are similar to classes in many ways. They have members and they can implement interfaces. They are fundamentally different from classes. STRUCTS are value types. STRUCT values are stored "on the stack" or "in-line". They cannot be inherited from any other class or reference type.
vi. Interfaces: What is an interface? An Interface simplifies a complex process by providing easy to use methods. Consider you need to change the channel on your TV or increase its volume, how do we do this, we use a Remote Control to change the channel or increase the volume. In this context, a Remote Control acts as an interface between you and your TV. Using a Remote Control one can perform required operation and control various functionality available in TV.

An interface defines a contract. When a class or a struct implements an interface with the help of methods and properties. A type (CLASS or STRUCT) that implements an interface must adhere to its contract. Interfaces can contain methods, properties, events, and indexers as members.

vii. Delegates: C# implements the functionality of function pointers using Delegates.

A delegate instance encapsulates a list of one or more methods, each of which is referred to as a callable entity. When a delegate instance is invoked it causes the delegate instance's callable entity to be invoked.

viii. Enums: An enum type declaration defines a type name for a related group of symbolic constants.











Download Getting Started with C#













Getting Started with C#



0 commentaires: