My Report

C# Programming Practice Test 1


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

1. Which is the String method used to compare two strings with each other?

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

 static void Main(string[] args)
 {
     int a = 4;
     int b = 5;
     int c = 6;
     int d = 8;
     if (((a * b / c) + d) >= ((b * c + d ) / a))
     {
         Console.WriteLine("Line 1 - a is greater to b");
         Console.WriteLine((a * b / c) + d);
     }
     else
     {
         Console.WriteLine("Line 1 - a is not greater to b");
         Console.WriteLine((b * c + d )/ a);
     }
 }

3. Which of the conversions are valid for the following C# code?

 static void Main(string[] args)
 {
     int a = 22;
     long b = 44;
     double c = 1.406;
     b = a;
     c = a;
     a = b;
     b = c;
 }

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

 class Program
 {
     public static void Main(string[] args)
     {
         int i = 100;
         for (a = 0; a < 5; a++)
         {
             int i = 200;
             Console. WriteLine(a * i);
         }
         Console. ReadLine();
     }
 }
  

5. DIFFERENCE BETWEEN KEYWORDS 'VAR' AND 'DYNAMIC'?

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

 
  public static void Main(string[] args)
  {
      int i = 546;
      object o = i;
      int n =(int) o;
      o = 70;
      System. Console. WriteLine("The value-type value = {0}", n);
      System. Console. WriteLine("The object-type value = {0}", o);
      Console. ReadLine();
  }
  

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

    int n = 2;
    int p = 4;
    int q = 5;
    int w = 3;
    if ( !((p * q) /n <= (q * w) + n/p ))
    {
        Console.WriteLine( ++p + w++ + " " + ++n);
        Console.WriteLine("b");
    }
    else
    {
        Console.WriteLine(--p + q-- + " " + --n);
        Console.WriteLine("a");
    }
 

8. Correct way to assign values to variable 'c' when int a=12, float b=3.5, int c;

9. Correct Declaration of Values to variables 'a' and 'b'?

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

static void Main(string[] args)
{
    string s1 = "Delhi";
    string s2;
    s2 = s1.Insert (6, "Jaipur");
    Console.WriteLine(s2);
}

 

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.