My Report (&Account)

C# Online Test


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)

Here is the complete list of test quizzes on C#.

1. Which of these classes is used to access actual bits or content information of a URL?

Question 1 of 50 (sanfoundry.com)

2. What will be the output of the following C# code?

 static void Main(string[] args)
 {
     String c = "Hello";
     String a = c + "Bye";
     Console.WriteLine(a);
     Console.ReadLine();
 }

Question 2 of 50 (sanfoundry.com)

3. Which of these keywords are used to implement synchronization?

Question 3 of 50 (sanfoundry.com)

4. Select the method which returns the number of bytes from the array buffer:

Question 4 of 50 (sanfoundry.com)

5. What will be the output of the following C# code?

 namespace ConsoleApplication4
 {
     public abstract class A
     {
         public int i = 7;
         public abstract void display();
     }    
     class B: A 
     {
         public int j;
         public override void display() 
         {
             Console.WriteLine(i);
             Console.WriteLine(j);
         }
     }    
     class Program
     {
         static void Main(string[] args)
         {
             B obj = new B();
             A obj1 = new B();
             obj.j = 1;
             obj1.i = 8;
             obj.display();
             Console.ReadLine();
         }
     }
 }  

Question 5 of 50 (sanfoundry.com)

6. What is the process by which we can control what parts of a program can access the members of a class?

Question 6 of 50 (sanfoundry.com)

7. What will be the output of the following C# code?

static void Main(string[] args)
{
    Program p = new Program();
    p.display(2, 3, 8);
    int []a = { 2, 56, 78, 66 };
    Console.WriteLine("example of array");
    Console.WriteLine("elements added are");
    p.display(a);
    Console.ReadLine();
}
public void display(params int[] b)
{
    foreach (int i in b)
    {
        Console.WriteLine("ARRAY IS HAVING:{0}", i);
    }
}

Question 7 of 50 (sanfoundry.com)

8. Choose the correct type of variable scope for the following C# defined variables.

  class ABC
  {
      static int m;
      int n;
      void fun (int x , ref int y, out int z, int[] a)
      {
         int j = 10;
      }
  }
 

Question 8 of 50 (sanfoundry.com)

9. Select the statement which are correct about RTTI(Runtime type identification)?

Question 9 of 50 (sanfoundry.com)

10. What exception is thrown if the URI format is invalid?

Question 10 of 50 (sanfoundry.com)

11. What will be the output of the following C# code snippet?

class Program
    {
        static void Main(string[] args)
        {

            int[] nums = { 1, -2, -3, 5 };
            var posNums = from n in nums
                          orderby n descending
                          select n*4 / 2;
            Console.Write("The values in nums: ");
            foreach (int i in posNums) Console.Write(i + " ");
            Console.WriteLine();
            Console.ReadLine();
        }
    }

Question 11 of 50 (sanfoundry.com)

12. Scope of variable is related to definition of variable as:
i. Region of code within which variable value is valid and hence can be accessed.
ii. No, relation with region where variable is declared its value is valid in entire scope.

Question 12 of 50 (sanfoundry.com)

13. Consider a class maths and we had a property called as sum.b is a reference to a maths object and we want the code below to work. Which is the correct solution to ensure this functionality?

b.maths = 10;
Console.WriteLine(b.maths);

Question 13 of 50 (sanfoundry.com)

14. If no access modifier for a class is specified, then class accessibility is defined as?

Question 14 of 50 (sanfoundry.com)

15. What does the following method specify?

   public static WebRequest Create(string requestUriString)

Question 15 of 50 (sanfoundry.com)

16. Which of these base class are accessible to the derived class members?

Question 16 of 50 (sanfoundry.com)

17. Which method in Console enables to read individual inputs directly from the keyboard in a non line buffered manner?

Question 17 of 50 (sanfoundry.com)

18. What exception is thrown if the user does not have a proper authorization?

Question 18 of 50 (sanfoundry.com)

19. Which C# statement should be added in function a() of class y to get output "i love csharp"?

 class x
 {
     public void a()
     {
         console.write("bye");
     }
 }
 class y : x
 {
     public void a()
     {
     /* add statement here */
         console.writeline("  i love csharp ");
     }
 }
 class program
 {
     static void main(string[] args)
     {
         y obj =  new obj();
         obj.a();
     }
 }

Question 19 of 50 (sanfoundry.com)

20. The correct code to access all the elements of the queue collection created using the following C#.NET code snippets?

Queue q = new Queue();
q.Enqueue("Harsh");
q.Enqueue('a');
q.Enqueue(false);
q.Enqueue(70);
q.Enqueue(8.5);

Question 20 of 50 (sanfoundry.com)

21. What will be the output of the following C# code?

  static void Main(string[] args)
  {
      int X = 0;
      if (Convert.ToBoolean(X = 0))
      Console.WriteLine("It is zero");
      else 
      Console.WriteLine("It is not zero");
      Console.ReadLine();
  }
 

Question 21 of 50 (sanfoundry.com)

22. What will be the output of the following C# code?

static void Main(string[] args)
{
  int[] a = {2, 21, 34, 46, 85, 88, 90};
  fun(a);
  Console.ReadLine();
}
static void fun(params int[] b)
{
  int[] c = {1, 2, 3, 4, 5, 6, 7};
  int i, j = 0;
  for (i = 0; i < b.Length; i++)
    if (b[i] % 2 == 0)
    {
      c[j++] = b[i];
    }

  for (i = 0; i < j; i++)
  {
    Console.Write(c[i] + " ");
  }
}

Question 22 of 50 (sanfoundry.com)

23. Which among the following differentiates enum in C#.NET from enum in C language?

Question 23 of 50 (sanfoundry.com)

24. What will be the output of the following C# code?

 static void Main(string[] args)
 {
     Console.WriteLine("This is a Console Application:");
     Console.Write("Please enter your lucky number:");
     string val1 = Console.ReadLine();
     int val2 = System.Convert.ToInt32(val1, 10);
     val2 = val2 * val2;
     Console.WriteLine("square of number is:" +val2);
     Console.Read();
 }

Question 24 of 50 (sanfoundry.com)

25. What will be the output of the following C# code?

 
  static void Main(string[] args)
  {
      float f;
      for (f = 0.1f; f <= 0.5; f += 1)
      Console.WriteLine( ++f );
      Console.ReadLine();
  }

Question 25 of 50 (sanfoundry.com)

26. What will be the output of the following C# code?

 
   string s1 = " I AM BEST ";
   string s2;
   s2 = s1.substring (5, 4);
   Console.WriteLine (s2);
 

Question 26 of 50 (sanfoundry.com)

27. Name the method/methods used to read byte streams from the file?

Question 27 of 50 (sanfoundry.com)

28. Select the correct match of parameter declaration.

 static Void main(string[] args)
 {
     int a = 5;
     int b = 6;
     float c = 7.2f;
     math (ref a, ref b, ref c);
     Console.WriteLine(a + "  " + b + "  " + c);
 }
 static int math(/*add parameter declaration */)
 {
     a += b;
     b *= (int)c;
     c += a * b;
     return 0;
 }

Question 28 of 50 (sanfoundry.com)

29. What will be the output of the following C# code?

   static void Main(string[] args)
   {
       int i = 1;
       while (i <= 1)
       {
           if ('A' < 'a')
           {
               Console.WriteLine("Hello...");
           }
           else
           {
              Console.WriteLine("Hi...");
           }
              i++;
       }
       Console.ReadLine();
   }
    

Question 29 of 50 (sanfoundry.com)

30. What will be the output of the following C# code snippet?

 class UnsafeCode
 {
     unsafe static void Main()
     {
         int m = 10;
         int *mptr = &m;
         int **ptr = &mptr;
         int n = 20;
         int *nptr = &n;
         int **prt = &nptr;
         m = **prt + *nptr;
         n = *mptr* **prt;
         Console.WriteLine(n + " " + m);
         Console.ReadLine();
     }
 }

Question 30 of 50 (sanfoundry.com)

31. The modifier used to hide the base class methods is?

Question 31 of 50 (sanfoundry.com)

32. Which among the following is considered as .NET Exception class?

Question 32 of 50 (sanfoundry.com)

33. What will be the output of the following C# code?

 public  static void Main(string[] args)
 {
     try
     {
         int a, b, c = 5;
         b = 0;
         a = c / b;
         Console.WriteLine("A");
     }
     catch (ArithmeticException e)
     {
         int c = 5;
         int i = 10;
         int z = 2 * c - i;
         Console.WriteLine("B");
         Console.WriteLine(z);
     }
     Console.ReadLine();
 }

Question 33 of 50 (sanfoundry.com)

34. Which of these is a correct way of defining generic method?

Question 34 of 50 (sanfoundry.com)

35. For two strings s1 and s2 to be equal, which is the correct way to find if the contents of two strings are equal?

Question 35 of 50 (sanfoundry.com)

36. What will be the output of the following C# code?

       
   static void Main(string[] args)
   {
       int x = 8;
       int b = 16;
       int C = 64;
       x /= b /= C /= x;
       Console.WriteLine(x + " " + b+ " " +C);
       Console.ReadLine();
   }
  

Question 36 of 50 (sanfoundry.com)

37. Which of the C# code should be added to get the following output?

 
    * * * * *
    * * * *
    * * *
    * *
    *
   static void Main(string[] args)
   {
       int i,j;
     /* Add code here */

  }
  

Question 37 of 50 (sanfoundry.com)

38. Given is the code of days(example:"MTWTFSS") which I need to split and hence create a list of days of week in strings( example:"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"). A set of code is given for this purpose but there is the error occurring in that set of code related to the conversion of char to strings. Hence, Select a C# code to solve the given error.

static void Main(string[] args)
{
    var days = "MTWTFSS";
    var daysArray = days.ToCharArray().Cast<string>().ToArray();
    for (var i = 0; i < daysArray.Length; i++)
    {
        switch (daysArray[i])
        {
        case "M":
            daysArray[i] = "Monday";
            break;
        case "T":
            daysArray[i] = "Tuesday";
            break;
        case "W":
            daysArray[i] = "Wednesday";
            break;
        case "R":
            daysArray[i] = "Thursday";
            break;
        case "F":
            daysArray[i] = "Friday";
            break;
        case "S":
            daysArray[i] = "Saturday";
            break;
        case "U":
            daysArray[i] = "Sunday";
            break;
        }
    }
    daysArray[daysArray.Length - 1] = "and " + daysArray[daysArray.Length - 1];
    Console.WriteLine(string.Join(", ", daysArray));
}

Question 38 of 50 (sanfoundry.com)

39. What will be the output of the following C# code?

  static void Main(string[] args)
  {
      int i = 0;
      if (i == 0)
      {
          goto label;
      }
      label: Console.WriteLine("HI...");
      Console.ReadLine();
  }
  

Question 39 of 50 (sanfoundry.com)

40. What will be the output of the following C# code snippet?

public class Generic<T>
{
    Stack<T> stk = new Stack<T>();
    public void push(T obj)
    {
        stk.Push(obj);
    }
    public T pop()
    {
        T obj = stk.Pop();
        return obj;
    }
}
class Program
{
    static void Main(string[] args)
    {
        Generic<string> g = new Generic<string>();
        g.push(30);
        Console.WriteLine(g.pop());
        Console.ReadLine();
    }
}

Question 40 of 50 (sanfoundry.com)

41. Which of these constructors is used to create an empty String object?

Question 41 of 50 (sanfoundry.com)

42. What will be the output of the following C# code snippet?

class UnsafeCode
{
    unsafe static void Main()
    {
        int[] nums = new int[10];
        fixed (int* p = &nums[0], p2 = nums)
        {
            if (p == p2)
            Console.WriteLine("p and p2 point to same address.");
            Console.ReadLine();
        }
    }
}

Question 42 of 50 (sanfoundry.com)

43. What will be the output of the following C# code snippet?

public class Generic<T>
{
    Stack<T> stk = new Stack<T>();
    public void push(T obj)
    {
        stk.Push(obj);
    }
    public T pop()
    {
        T obj = stk.Pop();
        return obj;
    }
}
class Program
{
    static void Main(string[] args)
    {
        Generic<string> g = new Generic<string>();
        g.push("C++");
        Console.WriteLine(g.pop() + " ");
        Generic<int> g1 = new Generic<int>();
        g1.push(20);
        Console.WriteLine(g1.pop());
        Console.ReadLine();
    }
}

Question 43 of 50 (sanfoundry.com)

44. Which of these data types is used by the operating system to manage the Recursion in Csharp?

Question 44 of 50 (sanfoundry.com)

45. Wrong statement about enum used in C#.NET is?

Question 45 of 50 (sanfoundry.com)

46. What will be the output of the following C# code?

 static void Main(string[] args)
 {
     int i;
     Console.WriteLine("enter value of i:");
     i = Convert.ToInt32(Console.ReadLine());
     if ( i % 2 == 0)
         goto even:
     else
     {
         Console.WriteLine("number is odd:");
         Console.ReadLine();
     }
     even:
     Console.WriteLine("number is even:");
     Console.ReadLine();
 }
for i = 4.

Question 46 of 50 (sanfoundry.com)

47. Select the statement which should be added to the current C# code to get the output as 10 20?

class baseclass
{
    protected int a = 20;
}
class derived : baseclass
{
    int a = 10;
    public void math()
    {
         /* add code here */
    }   
}

Question 47 of 50 (sanfoundry.com)

48. What will be the output of the following C# code?

  
 static void Main(string[] args)
 {
     m();
     Console.ReadLine();
 }
 static void m()
 {
     Console.WriteLine("HI");
     m();
 }

Question 48 of 50 (sanfoundry.com)

49. Which of the following statements is correct?

Question 49 of 50 (sanfoundry.com)

50. What will be the output of the following C# code?

 class maths 
 {
     int fact(int n) 
     {
         int result;
         if (n == 1)
         return 1;
         result = fact(n - 1) * n;
         return result;
     }
 } 
 class Output 
 {
     static void main(String args[]) 
     {
         maths obj = new maths() ;
         Console.WriteLine(obj.fact(1));
     }
 }

Question 50 of 50 (sanfoundry.com)


 

Topic wise Test Quizzes on C#

C# tests, quizzes, and exams are great ways to learn and test your C# programming skills. Whether you’re a beginner or experienced, challenge and boost your confidence with our engaging online quizzes on C# Basics, Data Types, Array, Classes, Interface, Delegate, Multithreading, Generic, and LINQ. Start the C# online test now!



C# Programming Certification Test

C# Programming Certification Test is a free certification exam. However, you need to score an A grade in each of the "Certification Level Tests 1 to 10" to be eligible to take part in this certification test. So, take all the "10 Tests" starting from Certification Level 1 upto Level 10, before taking the final Certification test.


Level 1 to 10 Tests:
Total Questions: 25, Total Time: 30 min, Correct Answer: 2 points, Wrong Answer: -1 point

Certification Test:
Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

C# Programming Internship Test

If you scored either Grade A* or Grade A in our C# Programming Internship Test, then you can apply for Internship at Sanfoundry in C# Programming.


Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

C# Programming Job Test

It is designed to test and improve your skills for a successful career, as well as to apply for jobs.


Total Questions: 50, Total Time: 1 hour, Correct Answer: 2 points, Wrong Answer: -1 point

Note: Before you get started on these series of online tests, you should practice our collection of 1000 MCQs on C# Programming .

Sanfoundry Scoring & Grading System

Sanfoundry tests and quizzes are designed to provide a real-time online exam experience. Here is what you need to know about them.

  • Scoring System: You get 2 points for each correct answer but lose 1 point for every wrong answer.
  • Grading System: Your grade depends on your final score and can be one of the following:

    • Grade A* - Genius (100%)
    • Grade A - Excellent (80% to 99%)
    • Grade B - Good (60% to 80%)
    • Grade C - Average (40% to 60%)
    • Grade D - Poor (0% to 40%)
advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 20s–40s and exploring new directions in your career, I also offer mentoring. Learn more here.