C# program to demonstrate the use of namespace
Program.cs
using Circle;
using Rectangle;

Circle.Shape s1 = new Circle.Shape();
Rectangle.Shape s2 = new Rectangle.Shape();
Console.WriteLine("———————————————————————————————————————————");
Console.WriteLine("Program to demonstrate the use of namespace");
Console.WriteLine("———————————————————————————————————————————");
Console.WriteLine("Area of a circle is " + s1.Area(5));
Console.WriteLine("Area of a rectangle is " + s2.Area(5, 2));
Console.WriteLine("———————————————————————————————————————————");

namespace Circle
{
    public class Shape
    {
        public static float PI = 3.14F;
        public float Area(float r)
        {
            float area = PI * r * r;
            return area;
        }
    }
}

namespace Rectangle
{
    public class Shape
    {
        public float Area(float l, float w)
        {
            float area = l * w;
            return area;
        }
    }
}
Output
kodingwindow@kw:~/csharp$ dotnet run
———————————————————————————————————————————
Program to demonstrate the use of namespace
———————————————————————————————————————————
Area of a circle is 78.5
Area of a rectangle is 10
———————————————————————————————————————————
kodingwindow@kw:~/csharp$ 
Advertisement