C# Questions & Answers ? Fundamentals of Namespaces
Posted by Superadmin on August 24 2022 05:56:09

C# Questions & Answers – Fundamentals of Namespaces

 

 

 

 

This section of our 1000+ C# MCQs focuses on namespaces fundamental in C# Programming Language.

 

 

 

 

1. Which of the following is not a namespace in the .NET Framework Class Library?
a) System.Process
b) System.Security
c) System.Threading
d) System.xml

Answer: a
Explanation: None.

 

 

 

2. Which is the correct statement about the namespaces in C#.NET?
a) Nesting of namespaces is permitted, provided all the inner namespaces are declared in the same file
b) A namespace cannot be tested
c) There is no limit on the number of levels while nesting namespaces
d) All of the mentioned

Answer: c
Explanation: None.

 

 

 

3. Which among the following does not belong to the C#.NET namespace?
a) class
b) struct
c) enum
d) data

Answer: d
Explanation: None.
 

 

 

 

4. Which among the following is a correct statement about namespace used in C#.NET?
a) Classes must belong to a namespace, whereas structures need not
b) All elements of the namespace must to belong to one file
c) If not mentioned, a namespace takes the name of the current project
d) All of the mentioned

Answer: c
Explanation: None.

 

 

 

 

5. Which among the given is not a correct way to call the method Issue() defined in the following C# code snippet?

  1.  class Book
  2. {
  3.     public void issue()
  4.     {
  5.       /* code */
  6.     }
  7. }
  8. class Journel
  9. {
  10.      public void issue()
  11.      {
  12.          /* code */
  13.      }
  14. }

a)

College.Lib.Book b = new College.Lib.Book();
b.issue();

b)

Book b = new Book();
b.issue();

c)

using College.Lib;
Book b = new Book();
b.issue();

d) All of the mentioned

Answer: b
Explanation: None.

6. Which among the following statements are not correct about a namespace used in C#.NET?
a) Nested namespaces are allowed
b) Importing outer namespaces imports inner namespace
c) Nested namespaces are allowed
d) Importing outer namespace does not import inner namespace

Answer: b
Explanation: None.

 

 

 

7. Which among the following is a .NET namespace?
a) System.Web
b) System.Process
c) System.Drawing2D
d) System.Drawing3D

Answer: a
Explanation: None.

 

 

 

 

8. If a class named csharp is present in namespace n1 as well as in namespace n2, then which of the following is the correct way to use csharp class?
a)

   class Program
   {
     static void Main(string[] args)
     {
        import n1;
        csharp x = new csharp();
        x.fun();
        import n2;
        csharp y = new csharp();
        y.fun();
     }
   }

b)

   import n1;
   import n2;
   namespace ConsoleApplication1
   {
      class Program
   {
     static void Main(string[] args)
     {
 
       n1.csharp x = new n1.csharp();
        x.fun();
        import n2;
        n2.csharp y = new n2.csharp();
        y.fun();
     }
   }
}

c)

   class Program
   {
     static void Main(string[] args)
     {
       using n1;
       csharp x = new csharp();
       x.fun();
       using n2;
       csharp y = new csharp();
        y.fun();
     }
   }

d)

   using n1;
   using n2;
   namespace ConsoleApplication1
   {
      class Program
   {
     static void Main(string[] args)
     {
 
       n1.csharp x = new n1.csharp();
        x.fun();
        import n2;
        n2.csharp y = new n2.csharp();
        y.fun();
     }
   }
}

 

Answer: c
Explanation: None.

 
 

 

 

 

9. If ListBox is the class of System.Windows.Forms namespace. Then, the correct way to create an object of ListBox class is?
a)

using System.Windows.Forms;
ListBox I = new ListBox();

b) System.Windows.Forms.ListBox I = new System.Windows.Forms.ListBox();
c) using LBControl I = new System.Windows.Forms.ListBox;
d) All of the mentioned

Answer: d
Explanation: None.

 

 

 

10. Which among the following is the correct statement about the using statement used in C#.NET?
a) A C#.NET source code file consists of any number of using statement
b) By using ‘using’ statement it’s possible to create an alias for the namespace but not for the namespace element
c) It is permitted to define a member at namespace level using alias
d) Using statement can be placed anywhere in the C#.NET source code file

Answer: c
Explanation: None.