C# Namespace Aptitude Questions and Answers | Set 4

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

1) Can we create more than one namespace in a single source code file?
  1. Yes
  2. No

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

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

    class program
    {
        static void Main(string[] args)
        {
            my_namespace1.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;

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

    class program
    {
        static void Main(string[] args)
        {
            my_namespace1.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)
        {
            sample.sayHello();
        }
    }
}
  1. Syntax error
  2. Hello
  3. Linker error
  4. Runtime exception

5) What is the correct output of the given code snippet?
using System;
using 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





Comments and Discussions!

Load comments ↻





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