Name space in #

1. It is a collection of variety of classes in a arranged manner.
2.A name space is used to organize your code and is collection of various classes ,interface,collection,enums,delefates etc.

System is a namespace and Console is a class in that namespace. The using keyword can be used so that the complete name is not required, as in the following example:


using System;
//We are using system name space.
//inside system namespace we have to describle console classess
class Program
{
    static void Main()//static Main method
    {
        Console.WriteLine("Hello My dear Friends");
        Console.Read();//Hold the screen
    }


}

O/p
Hello My dear Friends

//Here we are not using 'using' name space
class Program
{
    static void Main()//static Main method
    {
        System.Console.WriteLine("Hello My dear Friends");
        System.Console.Read();//Hold the screen
    }


}

O/p
Hello My dear Friends

Its a bad programing we should use name spaces 



using System;

class Program
{
    

    static void Main1(string[] args)//static  method
    {
        Console.WriteLine("Hello My dear Friends1");
        Console.Read();//Hold the screen
    }

    //Main method is the entry point of our application
    static void Main(string[] args)//static Main method
    {
        Console.WriteLine("Hello My dear Friends");
        Console.Read();//Hold the screen
    }


}

o/p
Hello My dear Friends


using System;

class Program
{
    

    static void Main1(string [] args)//static  method
    {
        Console.WriteLine("Hello My dear Friends1");
        Console.Read();//Hold the screen
    }

    //Main method is the entry point of our application
    static void Main(string[] args)//static Main method
    {
        Console.WriteLine("Hello My dear Friends");
        Console.Read();//Hold the screen
    }

    static void Main(string[] args)//static Main method
    {
        Console.WriteLine("Hello My dear Friends dublicate main method");
        Console.Read();//Hold the screen
    }


}

o/p

Two main method can not de define in single class (Error

Error 1 Type 'Program' already defines a member called 'Main' with the same parameter types C:\Users\jaideep.bisht\Documents\Visual Studio 2010\Projects\mvc project in series\Programing\Programing\Program.cs 20 17 Programing
)








Comments

Popular posts from this blog

Prime Number Program in C#

Fibonacci Series in C#

view in sql server