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();
        }
    }
}
        
            - Syntax error
- Hello
- Linker error
- Runtime exception
            Correct answer: 2
Hello
            The above code will print "Hello" on console screen.
         
    
   
    
        
        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();
        }
    }
}
        
            - Syntax error
- Hello
- Linker error
- Runtime exception
            Correct answer: 2
Hello
            The above code will print "Hello" on the console screen.
         
    
      
   
    
        
        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();
        }
    }
}
        
            - Syntax error
- Hello
- Linker error
- Runtime exception
            Correct answer: 1
Syntax error
            We cannot use using statement at the bottom of our program.
            The output would be,
    The name `sample' does not exist in the current context
         
    
   
    
        
        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();
        }
    }
}
        
            - Syntax error
- Hello
- Linker error
- Runtime exception
            Correct answer: 1
Syntax error
            We cannot use a namespace with :: in C#.NET.
            The output will be,
    Alias `my_namespace1' not found
         
    
   
 
    
        
        5) In C#.NET, is it possible that we can create a class with the same name in different namespaces?
        
            - Yes
- No
            Correct answer: 1
Yes
            Yes, it is possible.
         
    
   
    
    
    
    
	
    
    
    
  
    Advertisement
    
    
    
  
  
    Advertisement