×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

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



Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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