Home » Aptitude Questions and Answers » C# Aptitude Questions and Answers

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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.