logo

CuriousTab

CuriousTab

Discussion


Home C# Programming Functions and Subroutines See What Others Are Saying!
  • Question
  • 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

  • Correct Answer
  • 5 10 15 20 25 


  • More questions

    • 1. Which of the following are parts of the .NET Framework?

      1. The Common Language Runtime (CLR)
      2. The Framework Class Libraries (FCL)
      3. Microsoft Published Web Services
      4. Applications deployed on IIS
      5. Mobile Applications

    • Options
    • A. Only 1, 2, 3
    • B. Only 1, 2
    • C. Only 1, 2, 4
    • D. Only 4, 5
    • E. All of the above
    • Discuss
    • 2. For the code snippet given below, which of the following statements is valid?

      public class Generic<T>
      {
          public T Field;
      }
      class Program
      {
          static void Main(string[ ] args)
          {
              Generic<String> g = new Generic<String>();
              g.Field = "Hello";
              Console.WriteLine(g.Field);
          }
      }

    • Options
    • A. It will print string "Hello" on the console.
    • B. Name Generic cannot be used as a class name because it's a keyword.
    • C. Compiler will give an error.
    • D. Member Field of class Generic is not accessible directly.
    • E. None of the above.
    • Discuss
    • 3. Which of the following statements are correct about a delegate?

      1. Inheritance is a prerequisite for using delegates.
      2. Delegates are type-safe.
      3. Delegates provide wrappers for function pointers.
      4. The declaration of a delegate must match the signature of the method that we intend to call using it.
      5. Functions called using delegates are always late-bound.

    • Options
    • A. 1 and 2 only
    • B. 1, 2 and 3 only
    • C. 2, 3 and 4 only
    • D. All of the above
    • E. None of the above
    • Discuss
    • 4. For the code snippet given below, which of the following statements are valid?

      public class MyContainer<T> where T: class, IComparable
      {
          //Insert code here
      }
      1. Class MyContainer requires that it's type argument must implement IComparable interface.
      2. Compiler will report an error for this block of code.
      3. There are multiple constraints on type argument to MyContainer class.
      4. Class MyContainer requires that its type argument must be a reference type and it must implement IComparable interface.

    • Options
    • A. 1 and 2 Only
    • B. 3 and 4 Only
    • C. 2 and 3 Only
    • D. All of the above
    • E. None of the above
    • Discuss
    • 5. Which of the following will be the correct output for the C#.NET program given below?

      namespace CuriousTabConsoleApplication
      { 
          class SampleProgram
          { 
              static void Main(string[] args)
              {
                  int a = 5; 
                  int s = 0, c = 0;
                  Proc(a, ref s, ref c);
                  Console.WriteLine(s + " " + c);
              }
              static void Proc(int x, ref int ss, ref int cc)
              {
                  ss = x * x;
                  cc = x * x * x;
              } 
          } 
      }

    • Options
    • A. 0 0
    • B. 25 25
    • C. 125 125
    • D. 25 125
    • E. None of the above
    • Discuss
    • 6. Which of the following jobs are done by Common Language Runtime?

      1. It provides core services such as memory management, thread management, and remoting.
      2. It enforces strict type safety.
      3. It provides Code Access Security.
      4. It provides Garbage Collection Services.

    • Options
    • A. Only 1 and 2
    • B. Only 3, 4
    • C. Only 1, 3 and 4
    • D. Only 2, 3 and 4
    • E. All of the above
    • Discuss
    • 7. Which of the following statements are correct about the C#.NET code snippet given below?

      if (age > 18 && no < 11)
          a = 25;
      1. The condition no < 11 will be evaluated only if age > 18 evaluates to True.
      2. The statement a = 25 will get executed if any one condition is True.
      3. The condition no < 11 will be evaluated only if age > 18 evaluates to False.
      4. The statement a = 25 will get executed if both the conditions are True.
      5. && is known as a short circuiting logical operator.

    • Options
    • A. 1, 3
    • B. 2, 5
    • C. 1, 4, 5
    • D. 3, 4, 5
    • E. None of these
    • Discuss
    • 8. Which of the following are the correct way to initialise the variables i and j to a value 10 each?

      1. int i = 10; int j = 10;
      2. int i, j;
        i = 10 : j = 10;
      3. int i = 10, j = 10;
      4. int i, j = 10;
      5. int i = j = 10;

    • Options
    • A. 2, 4
    • B. 1, 3
    • C. 3, 5
    • D. 4, 5
    • Discuss
    • 9. What is the output of the C#.NET code snippet given below?

      namespace CuriousTabConsoleApplication
      {
          public enum color
          { red, green, blue };
          
          class SampleProgram
          {
              static void Main (string[ ] args)
              {
                  color c = color.blue;
                  switch (c)
                  {
                      case color.red:
                          Console.WriteLine(color.red); 
                          break; 
                      
                      case color.green: 
                          Console.WriteLine(color.green); 
                          break; 
                      
                      case color.blue: 
                          Console.WriteLine(color.blue); 
                          break; 
                  } 
              } 
          } 
      }

    • Options
    • A. red
    • B. blue
    • C. 0
    • D. 1
    • E. 2
    • Discuss
    • 10. Which of the following statements is correct about the C#.NET code snippet given below?

      switch (id)
      {
          case 6: 
              grp = "Grp B"; 
              break;
          
          case 13:
              grp = "Grp D";
              break;
          
          case 1:
              grp = "Grp A";
              break;
          
          case ls > 20:
              grp = "Grp E";
              break ;
          
          case Else:
              grp = "Grp F";
              break;
      }

    • Options
    • A. Compiler will report an error in case ls > 20 as well as in case Else.
    • B. There is no error in this switch case statement.
    • C. Compiler will report an error only in case Else.
    • D. Compiler will report an error as there is no default case.
    • E. The order of the first three cases should be case 1, case 6, case 13 (ascending).
    • Discuss


    Comments

    There are no comments.

Enter a new Comment