C# (pronounced "C sharp") is a simple, modern, object-oriented, and type-safe programming language. It will immediately be familiar to C and C++ programmers. C# combines the high productivity of Rapid Application Development (RAD) languages. The following are the advantages C# provides :-



  • Interactive Development Environment.

  • Visual designers for building Windows and Web applications.

  • Compiler.

  • Debugger.


 


Features of C# language:



  • Simple

  • Type safe

  • Versioning: making new version of an application from existing one to work.

  • Follows all OOPs paradigm

  • Automatic garbage collection

  • Flexible


Application Types in C#



  1. Class Library:- Creates a project for creating classes that can be used in other applications.

  2. Console Application:- Creates a Visual C# application with a command-line interface.

  3. Asp.Net Web Application:- Creates a Visual C# application with a Web user interface.

  4. Asp.Net Web Service:- Creates an XML Web service with Visual C# that other applications can access.

  5. Asp.Net Mobile Web Application:- Creates an application viewable on PDAs, cell phones, and other mobile devices.


 


Starting C#


using System;


using System.Collections.Generic;


using System.Windows.Forms;


 


namespace cSHARPEXAMPLES


{


  static class Program


    {


    /// <summary>


    /// The main entry point for the application.


    /// </summary>


    [ STAThread ]


    static void Main ()


        {


            Application .EnableVisualStyles();


            Application .SetCompatibleTextRenderingDefault( false );


            Application .Run( new Form1 ());


        }


    }


}


 


A C# program is divided into 4 parts:



  1. Namespace declaration:- This specifies the namespaces that we are going to use in the application. E.g. Using System;

  2. Class declaration:- Here we mentioned the starting class for this project or we can say that this is the entry point for our application.

  3. Main method:- The main method is the entry point of this application and here we can specify the form that we need to open first from this application Application .Run( new Form1 ()); // This line indicates that the control is passed to the instance of Form1() in the application once we start with the application.

  4. Comments:- The comments are given by // and /* */ block in the C# programs.


 


Compilation:- This project can be compiled through command prompt using the following command. The command will create a file called “Program.exe”, which we can execute.


 


Csc.exe Program.cs


 


Types in C#:-


 


C# supports two kinds of types: value types and reference types. Value types include simple types (e.g., char, int, and float), enum types, and struct types. Reference types include class types, interface types, delegate types, and array types.


 






























Value Types



Reference Types



Allocated on stack



Allocated on heap



A value type variable contains the data itself



Reference type variable contains the address of memory location where data is actually stored



When we copy a value type variable to another one, the actual data is copied and each variable can be independently manipulated.



When copying a reference type variable to another variable, only the memory address is copied. Both variables will still point to the same memory location, which means, if we change one variable, the value will be changed for the other variable too.



Integer, float, Boolean, double etc are value types.



String and object are reference types.



Struct is value type.



Classes and interfaces are reference types.



 

                    

Copyright © 2010 VisualBuilder. All rights reserved