logo

CuriousTab

CuriousTab

Discussion


Home C# Programming Collection Classes See What Others Are Saying!
  • Question
  • Which of the following is the correct way to access all elements of the Queue collection created using the C#.NET code snippet given below?

    Queue q = new Queue(); 
    q.Enqueue("Sachin"); 
    q.Enqueue('A'); 
    q.Enqueue(false); 
    q.Enqueue(38); 
    q.Enqueue(5.4);


  • Options
  • A.
    IEnumerator e;
    e = q.GetEnumerator(); 
    while (e.MoveNext())
    Console.WriteLine(e.Current);
  • B.
    IEnumerable e;
    e = q.GetEnumerator(); 
    while (e.MoveNext()) 
    Console.WriteLine(e.Current);
  • C.
    IEnumerator e;
    e = q.GetEnumerable(); 
    while (e.MoveNext()) 
    Console.WriteLine(e.Current);
  • D.
    IEnumerator e;
    e = Queue.GetEnumerator(); 
    while (e.MoveNext()) 
    Console.WriteLine(e.Current);

  • Correct Answer
  • IEnumerator e;
    e = q.GetEnumerator(); 
    while (e.MoveNext())
    Console.WriteLine(e.Current);
     


  • More questions

    • 1. A class implements two interfaces each containing three methods. The class contains no instance data. Which of the following correctly indicate the size of the object created from this class?

    • Options
    • A. 12 bytes
    • B. 24 bytes
    • C. 0 byte
    • D. 8 bytes
    • E. 16 bytes
    • Discuss
    • 2. Which of the following keyword is used to change the data and behavior of a base class by replacing a member of a base class with a new derived member?

    • Options
    • A. new
    • B. base
    • C. overloads
    • D. override
    • E. overridable
    • Discuss
    • 3. Which of the following statements are correct about an interface in C#.NET?

      1. A class can implement multiple interfaces.
      2. Structures cannot inherit a class but can implement an interface.
      3. In C#.NET, : is used to signify that a class member implements a specific interface.
      4. An interface can implement multiple classes.
      5. The static attribute can be used with a method that implements an interface declaration.

    • Options
    • A. 1, 2, 3
    • B. 2, 4
    • C. 3, 5
    • D. None of the above.
    • Discuss
    • 4. Which of the following should be used to implement a 'Like a' or a 'Kind of' relationship between two entities?

    • Options
    • A. Polymorphism
    • B. Containership
    • C. Templates
    • D. Encapsulation
    • E. Inheritance
    • Discuss
    • 5. Which of the following is NOT an Exception?

    • Options
    • A. StackOverflow
    • B. Division By Zero
    • C. Insufficient Memory
    • D. Incorrect Arithmetic Expression
    • E. Arithmetic overflow or underflow
    • Discuss
    • 6. Which of the following can implement an interface?

      1. Data
      2. Class
      3. Enum
      4. Structure
      5. Namespace

    • Options
    • A. 1, 3
    • B. 2, 4
    • C. 3, 5
    • D. 4 only
    • Discuss
    • 7. It is compulsory for all classes whose objects can be thrown with throw statement to be derived from System.Exception class.

    • Options
    • A. True
    • B. False
    • Discuss
    • 8. What will be the output of the C#.NET code snippet given below?

      namespace CuriousTabConsoleApplication
      { 
          class SampleProgram
          { 
              static void Main(string[] args)
              { 
                  int[]arr = newint[]{ 1, 2, 3, 4, 5 }; 
                  fun(ref arr);
              }
              static void fun(ref int[] a)
              { 
                  for (int i = 0; i < a.Length; i++)
                  { 
                      a[i] = a[i] * 5; 
                      Console.Write(a[ i ] + " "); 
                  } 
              } 
          } 
      }

    • Options
    • A. 1 2 3 4 5
    • B. 6 7 8 9 10
    • C. 5 10 15 20 25
    • D. 5 25 125 625 3125
    • E. 6 12 18 24 30
    • Discuss
    • 9. Which of the following keyword is used to overload user-defined types by defining static member functions?

    • Options
    • A. op
    • B. opoverload
    • C. operator
    • D. operatoroverload
    • E. udoperator
    • Discuss
    • 10. Which of the following is the correct way of setting values into the structure variable e defined below?

      struct Emp
      {
          public String name;
          public int age;
          public Single sal; 
      }
      Emp e = new Emp();

    • Options
    • A.
      e.name = "Amol"; 
      e.age = 25; 
      e.sal = 5500;
    • B.
      With e
      {
          .name = "Amol";
          .age = 25;
          .sal = 5500; 
      }
    • C.
      With emp e
      {
          .name = "Amol";
          .age = 25;
          .sal = 5500; 
      }
    • D.
      e -> name = "Amol"; 
      e -> age = 25;
      e -> sal = 5500;
    • E.
      name = "Amol"; 
      age = 25;
      sal = 5500;
    • Discuss


    Comments

    There are no comments.

Enter a new Comment