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

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

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.