My Report

C# String Test – 3


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. What will be the output of the following C# code?

 class Program
 {
     static void Main(string[] args)
     { 
         String c = "i love Csharp";
         bool a;
         a = c.StartsWith("I");
         Console.WriteLine(a);
         Console.ReadLine();
     }
 }

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

class Program
{
    static void Main(string[] args)
    { 
        String s1 = "I love You";
        String s2 = s1;
        Console.WriteLine((s1 == s2) + " " + s1.Equals(s2));
        Console.ReadLine();
    }
}

3. Which of these data type values is returned by equals() method of String class?

4. Which of these methods is used to compare two strings such that after comparison output returns different integer values as (0 for false, 1 for true)?

5. What is the value returned by function compareTo() if the invoking string is less than the string compared?

6. Which of these methods returns the string such that some characters which are specified to be removed from the end of strings are removed from string by mentioning the number of characters to be removed?

7. Which of these methods of class String is used to compare two String objects for their equality?

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

 class Program
 {
     static void Main(string[] args)
     { 
         String []chars = {"z", "x", "y", "z", "y"};
         for (int i = 0; i < chars.Length; ++i)
         for (int j = i + 1; j < chars.Length; ++j)
         if(chars[i].CompareTo(chars[j]) == 0)
         Console.WriteLine(chars[j]);
         Console.ReadLine();
     }
 }

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

String a = "Csharp";
String b = "CSHARP";
int c;
c = a.CompareTo(b);
Console.WriteLine(c);

10. Which of these methods of class String is used to check whether a substring exists at the beginning of the particular string?


 

Start practicing “1000 MCQs on C#”, and once you are ready, you can take tests on all topics by attempting our “C# Test Series”.

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.