Advertisement

Overview of C#

By Bintu Chaudhary   Posted at  7:43:00 AM   Overview of C#

Home  »  C#  »  Overview of C#


C# Provides us Making two Types of Programs either Executable Programs or either For another Applications The Programs which contains Main Method are called as Standalone Programs and they may used by another Applications. We know that C# is a Pure Object –Oriented Language so that Every Program of C# is Written into the Classes A Simple Program of C# is as Follows:-

Class abc
{
  Public static void Main()
  {
    System.Console.WriteLine("Welcome C-Sharp");
  }
}

1) We know C# is Purely OOP Language So that Every Program of C# Must be Written into the Classes For this Class is Keyword and abc is name of Class

The Main Line
    Public static void Main() is the main Line of the C-Sharp program

Public
    Here Public is a Keyword which declares main method is public or unprotected so that it will be Accessible to all classes and main can be Accessed from Outside Means data which is Declared in the Main Can be Called from outside the Program

Static
    Static is used for Describing that Method is Called without Creating any Object of Class and this is directly Accessed and This Specifies the Main Entry Point For Execution For Compiler . A Compiler will understand that this is the Only One Execution Point For Executing the Statements

Void
    Void means The Main Function will never Return a Value or it will Simply Prints the text on the Screen

Contents



Namespaces

     In C# System is the namespace in which all the Classes of C# are Located or you can Name Space is Package Which Contains Collection of Classes and their Associated Methods For Using Any Method From Any Class we have to Specify the name of Class and with the Help of dot . Operator we can call any Method of Class But This is very Big Problem for a user to Write a Same Line Again and Again or This is very difficult for a user to Write a Long Name So for This Reason a user can Give am Alias or a Short Name to a Name Space Name But For doing this Thing using directive Must be Used along with the name of the Name Space Like This

namespace ProjectOne
{
   using System
   using System.Drawing;
   using System.Collections;
   using System.ComponentModel;
   using System.WinForms;
   using System.Data;
}

System.Console.WriteLine or Output Line

     This Line is Similar to printf in C and Cout in C++ For Displaying the Results on the Screen at the Time of Execution in this Console is the name of class which is Located in the System Namespace and WriteLine is the Name of Method which is Stored in Console Class and WriteLine Always Creates or Append a New Line After Executing a Statement.

   Once Installed C# on your System we can create a Program of C# in any drive and from any where we can call a C# Program and For Compiling a C-Sharp Program we have to use the C# Compiler Which is Knows as CSC or Simply C# Compiler and After the Compilation this will create an Executable File not any Object file and we can Execute that File Directly by just giving the name of File.

Adding Comments

     Comments are used for only user displaying an idea for other users how the Processing instructions will be Executed or what's the Meaning of Statements So for This A user can give Comments for describing his Program But Always Remember Comment Lines are never to be Executed and For Giving a Comment to a Line A user can use // for a Single Line Comment and / * , */ for Multiple Lines as we do in other Languages.

//Single Line Comment
/* Multiple Line Comment */

Command Line Arguments

     There is Situation . when output of a program is depend on input of another program So for providing the input , C# provides us Command line Arguments These are the parameters those are provided at Run Time or when we Interpret C# program for Execution But Always Remember these are Always String by default C# also provide us Length Method which is built in Method for calculating the Length of Arguments those are supplied at the Time of Execution . Any thing which is Supplied in Command Line is given in the String so we have to Convert the Strings into Number if we wants to use Numeric Values For Converting String into Numbers we have to use int.Parse Method.

using System;
class Hello
{
  public static void Main(string [] args)
  {
    for(int i = 0; i < args.Length; i++)
    Console.WriteLine(Arg{0}",args[i]);
  }
}

Multiple Main Methods

     Generally there are Only one Main Method in Programming Languages This will Create a big Problem For a user to store his Programs in different-2 Files So that C# Solve this Problem and this provides us the Facility for a user to use Multiple Main Methods or in a Single Program a user can Store Multiple Programs in a Single Programs or in a Single Programs Multiple Main Methods are there so for this a user might decide which program he wants to be Execute and at the Time of Compilation he can Specify the Name of Class or Name of Class which A Main Method Resides and then that Program will be Executed.

//Multiple Main Methods
using System;
class A
{
  public static void Main()
  {
    Console.WriteLine("First Class");
  }
}
class B
{
  public static void Main()
  {
    Console.WriteLine("Second Class");
  }
}
class C
{
  public static void Main()
  {
    Console.WriteLine("Third Class");
  }
}


Compile=> If A Class -> csc A.cs/main:A
Run=> A
If B Class-> csc A.cs/main:b
A
if C Class-> csc A.cs/main:c
A

Programming Style

     C# is a free Form Programming Language which allows a user to write his Code in a Free Form Means he Can Write a Single Line into Multiple Lines but Always Remember a user cant Break the Name Class from a Namespace he can only break only quotes ,dot and Open Parenthesis etc.
Like this

System.Console.WriteLine(" Hello " );

Program: For Writing any Instruction a user have to write a Program. A Program Contains Many Statements Which Further Contains Variables, Constants, Operator etc. Special Characters etc . Generally a Program Contains





About the Author

Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.
View all posts by: BT9

Back to top ↑
Connect with Me