My Report

C# String Test – 2


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?

 static void Main(string[] args)
 {
     String obj = "hello";
     String obj1 = "world";   
     String obj2 = obj;
     string s = obj+" "+obj1;
     Console.WriteLine(s.IndexOf('r'));
     Console.ReadLine();
 }

2. Correct way to convert a string to uppercase using string class method()?

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

 static void Main(string[] args)
 {
     String obj = "hello";
     String obj1 = "world";   
     String obj2 = obj;
     Console.WriteLine(obj + "  " + obj1);
     string s = obj + "  " + obj1;
     Console.WriteLine(s.Length);
     Console.ReadLine();
 } 

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

 static void Main(string[] args)
 {
     String obj = "hello";
     String obj1 = "worn";   
     String obj2 = obj;
     Console.WriteLine(obj + "  " + (obj1.Replace('w' ,'c')));
     Console.ReadLine();
 }

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

 static void Main(string[] args)
 {
     String obj = "hello";
     String obj1 = "world";   
     String obj2 = obj;
     string s = obj + "  " + obj1;
     Console.WriteLine(s.Substring(6 ,5));
     Console.ReadLine();
 }

6. To perform comparison operation on strings supported operations are ____________

7. What does the term 'immutable' means in term of string objects?

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

 
 static void Main(string[] args)
 {
     string s1 = "Hello I Love Csharp ";
     Console.WriteLine(Convert.ToChar( (s1.IndexOf('I') - s1.IndexOf('l')) * s1.IndexOf('p'));
     Console.ReadLine();
 }

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

 
 static void Main(string[] args)
 {
     String obj = "hello";
     String obj1 = "world";   
     String obj2 = obj;
     Console.WriteLine (obj.Equals(obj2) + "  " + obj2.CompareTo(obj) );
     Console.ReadLine();
 }

10. What is the String in C# meant for?


 

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.