Overview of C#

By
C# Program:- The best way to learn any language is to write a simple program and execute them.With the help of program we can easily analyze and understand how this works.C# codes are given below:
class student
    {
        static void Main()
        {
            System.Console.WriteLine("Students are future of any country");
           /* System.Console.WriteLine("Hello student");*/
           // System.Console.WriteLine("Hello Employee"); 
            System.Console.ReadLine();
        }
    }
Description:-There are some descriptions of programs which is given below:

  1. Class Declaration:-C# is a object oriented programming language therefore all codes must be placed inside a class.Class is a keyword and Class Name 'student' is an identifier.
  2. The Braces:-In c# we have used two types of braces.
  • Opening braces (Ex.{ )
  • Closing braces  (Ex. } )
Opening braces starts with beginning of any class in C# and closing braces are used at the end of the class.
     3.  The Main Method:- Every c# program has a Main Method.Every class which is defined outside always called from the Method.Every program starts execution from the Main Method.
Ex.
 static void Main(string[] args)
{
----------------------------------------
}
       4. The Output Line:-Write Line is a static method of console class.System is a Namespace. Console class resides within this Namespace.
Ex.
System.Console.WriteLine("Students are future of any country";
5. The Comments:-Comments play important role in C# program.It is used for Maintenance of programs.
There are two types of comments
  • Single Line comments
Ex. /* System.Console.WriteLine("Hello student");*/
  • Double Line comments
Ex. // System.Console.WriteLine("Hello Employee");
     6. The Return Type:-In above program Main method is not Returning any value because it return type is 'void'.If its return type is 'int' then it will return a integer type value. I will give the  example in Next Program.
     7. Namespace:- I above program System is a Namespace and Console class resides within this Namespace.We can write above program in different way using Namespace.
see it:
using System;
 class student
    {
        static int Main()
        {
            Console.WriteLine("Students are future of any country");
            /* System.Console.WriteLine("Hello student");*/
            // System.Console.WriteLine("Hello Employee"); 
            System.Console.ReadLine();
            return 0;
        }
    }
Note:-In above program Main Method is returning a Integer type value.Remember,Write Line Method takes always a String value.
     8. Aliases:-If we want to avoid prefix ("System.Console") Namespace and class then we can use  an alternate(user defined) Name.
Ex.
using R= System.Console;
 class student
    {
        static int Main()
        {
            R.WriteLine("Students are future of any country");
            /* R.WriteLine("Hello student");*/
            // R.WriteLine("Hello Employee"); 
               R.ReadLine();
            return 0;
        }
    }

Take Input From User:- There are two way to take Input from User.
  1. Using command Line arguments.
  2. Using assignment operators.
     1. ) Command Line arguments:- In command Line arguments parameters are directly    passed to the Main Method at the time of Execution of Programs.
Ex.
using System;
    class student
    {
        static void Main(string[] args)
        {
            Console.WriteLine("ARRAY VALUES");
            Console.WriteLine("array first element is:" + args[0]);
            Console.WriteLine("array second element is:" + args[0]);
            Console.WriteLine("array third element is:" + args[0]);
            Console.ReadLine();
        }
    }

Description:- in above Example Main Method is declared with parameter args.The parameter
args is declared as an array of strings.
when we execute the program through command line then we will write following codes.
 student ram mohan ajay
The command Line arguments contains three values which are assigned to to the array args as following:-
args[0]<---ram
args[1]<---mohan
args[2]<---ajay
Output of the program wil be:
ARRAY VALUES
array first element is:ram
array second element is:mohan
array third element is:ajay
     2. )  Using Assignments operators:- In assignments operators ,we takes input from console and store it in a variable as given below:
using System;
    class student
    {
        static void Main()
        {
            Console.WriteLine("Enter two Integer values");
            int l= int.Parse(Console.ReadLine());
            int w = int.Parse(Console.ReadLine());
            int res= l * w;
            Console.WriteLine("Rectangle area is"+" "+res);
            Console.ReadKey();
        }
    }


output:
For More:

  1. Tokens in C#
  2. Variables and Data type in c#
  3. Operators in C#
  4. Decision making &Lopping in C#
  5. Type conversion in C#
  6. Arrays in C#

To Get the Latest  Free Updates Subscribe
Click below for download whole program
            Download

0 comments:

Post a Comment

Powered by Blogger.