Q:

C# program to create a user defined the namespace

0

C# program to create a user defined the namespace

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to create a user define namespace is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to create a user defined the namespace

using System;

namespace Test.Namespace
{
    class Sample
    {
        public static void Swap(ref int X, ref int Y)
        {
            int Z = 0;

            Z = X;
            X = Y;
            Y = Z;
        }
    }
}
class Program
{
    static void Main()
    {
        int X = 10;
        int Y = 20;

        Console.WriteLine("Before swapping : X " + X + ", Y " + Y);
        Test.Namespace.Sample.Swap(ref X, ref Y);

        Console.WriteLine("After swapping  : X " + X + ", Y " + Y);
        Console.WriteLine();
    }
}

Output:

Before swapping : X 10, Y 20
After swapping  : X 20, Y 10

Press any key to continue . . .

Explanation:

In the above program, we created a user-defined namespace "Test.Namespace" that contains a Sample class. The Sample class contains a Swap() method. The Swap() method will interchange the values of parameters with each other.

Here we also created a Program class that contains the Main() method. In the Main() method, we created two local variables X and Y. Then swap the values using the Swap() method and print the swapped value on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | Class, Object, Methods

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to demonstrate the use of #define prepr... >>
<< C# program to terminate the current running progra...