C# Namespace Aptitude Questions and Answers | Set 5

C# Namespace Aptitude Questions | Set 5: This section contains aptitude questions and answers on C# Namespace.
Submitted by Nidhi, on April 08, 2020

1) What is the correct output of the given code snippet?
using System;
using my_namespace2.my_namespace1;

namespace my_namespace2
{

    namespace my_namespace1
    {
        class sample
        {
            public static void sayHello()
            {
                Console.WriteLine("Hello");
            }
        }
    }

    class program
    {
        static void Main(string[] args)
        {
            sample.sayHello();
        }
    }
}
  1. Syntax error
  2. Hello
  3. Linker error
  4. Runtime exception

2) What is the correct output of the given code snippet?
using System;

namespace my_namespace2
{
    using my_namespace2.my_namespace1;
    namespace my_namespace1
    {
        class sample
        {
            public static void sayHello()
            {
                Console.WriteLine("Hello");
            }
        }
    }

    class program
    {
        static void Main(string[] args)
        {
            sample.sayHello();
        }
    }
}
  1. Syntax error
  2. Hello
  3. Linker error
  4. Runtime exception

3) What is the correct output of the given code snippet?
using System;

namespace my_namespace2
{
    namespace my_namespace1
    {
        class sample
        {
            public static void sayHello()
            {
                Console.WriteLine("Hello");
            }
        }
    }

    class program
    {
        static void Main(string[] args)
        {
            sample.sayHello();
        }
    }
}
  1. Syntax error
  2. Hello
  3. Linker error
  4. Runtime exception

4) What is the correct output of the given code snippet?
using System;

namespace my_namespace2
{
    namespace my_namespace1
    {
        class sample
        {
            public static void sayHello()
            {
                Console.WriteLine("Hello");
            }
        }
    }

    class program
    {
        static void Main(string[] args)
        {
            my_namespace1::sample.sayHello();
        }
    }
}
  1. Syntax error
  2. Hello
  3. Linker error
  4. Runtime exception

5) In C#.NET, is it possible that we can create a class with the same name in different namespaces?
  1. Yes
  2. No





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.