Sponsored Ad

Monday, September 28, 2009

C# Namespace

A Namespace in Microsoft .Net is like containers of objects.They may lath unions, classes, structures, interfaces, enumerators and delegates. Main appetence of apparatus namespace in .Net is for creating a hierarchical alignment of program. In this case a developer does not allegation to affliction about the allocation conflicts of classes, functions, variables etc., axial a project. In Microsoft .Net, every address is created with a absence namespace. This absence namespace is declared as all-around namespace.But the address itself can accede any bulk of namespaces, ceremony of them with a adapted name. The advantage is that every namespace can board any bulk of classes, functions, variables and aswell namespaces etc. whose names are adapted alone axial the namespace. The accumulation with the aloft name can be created in some added namespace afterwards any compiler complaints from Microsoft .Net.

To acknowledge namespace C# .Net has a aloof keyword namespace. If a new activity is created in Visual Studio .NET it automatically adds some all-around namespaces. These namespaces can be different in different projects. But each of them should be placed under the base namespace System. The names space must be added and used through the using operator, if used in a different project.

namespace Math
{
    class Addition
    {
        static public double add(params int[] numbers)
        {
            int total = 0;
            for(int i=0; i<numbers.Length; i++)
            {
                total += numbers[i];
            }   
            return total;
        }
    }
}

class MyMath
{
    public static void Main()
    {
        double x = Math.Addition.add(1, 3, 5, 6);       
        System.Console.WriteLine(x);
    }
}

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers