C Sharp Strings Questions and Answers

Take Exam

C# Strings are one of the most important topics in programming interviews and technical tests. This page features C# programming questions and answers focused on string manipulation, methods, immutability, and performance optimization. These C# strings questions with answers are ideal for students preparing for TCS, Infosys, Wipro, and Capgemini placement exams. Understanding string operations in C# helps programmers efficiently manage text data and avoid common pitfalls related to memory and performance.

C Sharp Strings

Showing 10 of 32 questions

1. Which of the following statements are true about the C#.NET code snippet given below? String s1, s2; s1 = "Hi"; s2 = "Hi";     String objects cannot be created without using new.     Only one object will get created.     s1 and s2 both will refer to the same object.     Two objects will get created, one pointed to by s1 and another pointed to by s2.     s1 and s2 are references to the same object.

  • 1, 2, 4
  • 2, 3, 5
  • 3, 4
  • 2, 5
Show Answer Report

2. Which of the following will be the correct output for the C#.NET code snippet given below? String s1 = "ALL MEN ARE CREATED EQUAL"; String s2; s2 = s1.Substring(12, 3); Console.WriteLine(s2);

  • ARE
  • CRE
  • CR
  • REA
Show Answer Report

3. Which of the following statements will correctly copy the contents of one string into another ?

  • String s1 = "String"; String s2; s2 = s1;
  • String s1 = "String" ; String s2; s2 = String.Concat(s1, s2);
  • String s1 = "String"; String s2; s2 = String.Copy(s1);
  • String s1 = "String"; String s2; s2 = s1.Replace();
Show Answer Report

4. The string built using the String class are immutable (unchangeable), whereas, the ones built- using the StringBuilder class are mutable.

  • True
  • False
Show Answer Report

5. Which of the following will be the correct output for the C#.NET code snippet given below? String s1 = "Nagpur"; String s2; s2 = s1.Insert(6, "Mumbai"); Console.WriteLine(s2);

  • NagpuMumbair
  • Nagpur Mumbai
  • Mumbai
  • Nagpur
Show Answer Report

6. If s1 and s2 are references to two strings, then which of the following is the correct way to compare the two references?

  • s1 is s2
  • s1 = s2
  • s1 == s2
  • strcmp(s1, s2)
Show Answer Report

7. Which of the following will be the correct output for the C#.NET code snippet given below? String s1="Kicit"; Console.Write(s1.IndexOf('c') + " "); Console.Write(s1.Length);

  • 3 6
  • 2 5
  • 3 5
  • 2 6
Show Answer Report

8. Which of the following is correct way to convert a String to an int?     String s = "123";     int i;     i = (int)s;     String s = "123";     int i;     i = int.Parse(s);     String s = "123";     int i;     i = Int32.Parse(s);     String s = "123";     int i;     i = Convert.ToInt32(s);     String s = "123";     int i;     i = CInt(s);

  • 1, 3, 5
  • 2, 4
  • 3, 5
  • 2, 3, 4
Show Answer Report

9. Which of the following statements about a String is correct?

  • A String is created on the stack.
  • Whether a String is created on the stack or the heap depends on the length of the String.
  • A String is a primitive.
  • A String can be created by using the statement String s1 = new String;
Show Answer Report

10. Which of the following statement is correct about a String in C#.NET?

  • A String is mutable because it can be modified once it has been created.
  • Methods of the String class can be used to modify the string.
  • A number CANNOT be represented in the form of a String.
  • A String has a zero-based index.
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test