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

  • A) True
  • B) False

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

  • A)
    s1 is s2
  • B)
    s1 = s2
  • C)
    s1 == s2
  • D)
    strcmp(s1, s2)
  • E)

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

  • A) A String is created on the stack.
  • B) Whether a String is created on the stack or the heap depends on the length of the String.
  • C) A String is a primitive.
  • D) A String can be created by using the statement String s1 = new String;
  • E) A String is created on the heap.

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

  • A) A String is mutable because it can be modified once it has been created.
  • B) Methods of the String class can be used to modify the string.
  • C) A number CANNOT be represented in the form of a String.
  • D) A String has a zero-based index.
  • E) The System.Array class is used to represent a string.

5. What is the difference between System.String and System.StringBuilder classes?  

System. String is immutable; System.StringBuilder can have mutable string where a variety of operations can be performed.

6. What is the difference between string keyword and System.String class?  

String keyword is an alias for System.String class. Therefore, System.String and string keyword are the same, and you can use whichever naming convention you prefer. The String class provides many methods for safely creating, manipulating, and comparing strings.

7. Why are strings in C# immutable?  

Immutable means string values cannot be changed once they have been created. Any modification to a string value results in a completely new string instance, thus an inefficient use of memory and extraneous garbage collection. The mutable System.Text.StringBuilder class should be used when string values will change.

8. How do you initiate a string without escaping each backslash?  

You put an @ sign in front of the double-quoted string.
String ex = @"This has a carriage return\r\n"

.Net Interview Question

PHP Interview Question

Java Interview Question

AngularJS Interview Questions