logo

CuriousTab

CuriousTab

Discussion


Home C# Programming Strings Comments

  • Question
  • Which of the following statements will correctly copy the contents of one string into another?


  • Options
  • A.
    String s1 = "String";
    String s2; 
    s2 = s1;
  • B.
    String s1 = "String" ; 
    String s2;
    s2 = String.Concat(s1, s2);
  • C.
    String s1 = "String"; 
    String s2;
    s2 = String.Copy(s1);
  • D.
    String s1 = "String"; 
    String s2;
    s2 = s1.Replace();
  • E.
    String s1 = "String"; 
    String s2;
    s2 = s2.StringCopy(s1);

  • Correct Answer
  • String s1 = "String"; 
    String s2;
    s2 = String.Copy(s1);
     


  • Strings problems


    Search Results


    • 1. If s1 and s2 are references to two strings then which of the following are the correct ways to find whether the contents of the two strings are equal?

      1. if(s1 = s2)
      2. if(s1 == s2)
      3. int c;
        c = s1.CompareTo(s2);
      4. if( strcmp(s1, s2) )
      5. if (s1 is s2)

    • Options
    • A. 1, 2
    • B. 2, 3
    • C. 4, 5
    • D. 3, 5
    • Discuss
    • 2. Which of the following statements are correct about the String Class in C#.NET?

      1. Two strings can be concatenated by using an expression of the form s3 = s1 + s2;
      2. String is a primitive in C#.NET.
      3. A string built using StringBuilder Class is Mutable.
      4. A string built using String Class is Immutable.
      5. Two strings can be concatenated by using an expression of the form s3 = s1&s2;

    • Options
    • A. 1, 2, 5
    • B. 2, 4
    • C. 1, 3, 4
    • D. 3, 5
    • Discuss
    • 3. Which of the following statements about a String is correct?

    • Options
    • 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.
    • Discuss
    • 4. The string built using the String class are immutable (unchangeable), whereas, the ones built- using the StringBuilder class are mutable.

    • Options
    • A. True
    • B. False
    • Discuss
    • 5. If s1 and s2 are references to two strings, then which of the following is the correct way to compare the two references?

    • Options
    • A. s1 is s2
    • B. s1 = s2
    • C. s1 == s2
    • D. strcmp(s1, s2)
    • E. s1.Equals(s2)
    • Discuss
    • 6. What will be the output of the C#.NET code snippet given below?

      namespace CuriousTabConsoleApplication
      {
          class SampleProgram
          {
              static void Main(string[ ] args)
              {
                  string str= "Hello World!";
                  Console.WriteLine( String.Compare(str, "Hello World?" ).GetType() );
              }
          }
      }

    • Options
    • A. 0
    • B. 1
    • C. String
    • D. Hello World?
    • E. System.Int32
    • Discuss
    • 7. Which of the following is the correct way to find out the index of the second 's' in the string "She sells sea shells on the sea-shore"?

    • Options
    • A.
      String str = "She sells sea shells on the sea-shore"; 
      int i;
      i = str.SecondIndexOf("s");
    • B.
      String str = "She sells sea shells on the sea-shore"; 
      int i, j;
      i = str.FirstIndexOf("s"); 
      j = str.IndexOf("s", i + 1);
    • C.
      String str = "She sells sea shells on the sea-shore"; 
      int i, j;
      i = str.IndexOf("s"); 
      j = str.IndexOf("s", i + 1);
    • D.
      String str = "She sells sea shells on the sea-shore"; 
      int i, j;
      i = str.LastIndexOf("s"); 
      j = str.IndexOf("s", i - 1);
    • E.
      String str = "She sells sea shells on the sea-shore"; 
      int i, j;
      i = str.IndexOf("S"); 
      j = str.IndexOf("s", i);
    • Discuss
    • 8. Which of the following statements are correct?

      1. String is a value type.
      2. String literals can contain any character literal including escape sequences.
      3. The equality operators are defined to compare the values of string objects as well as references.
      4. Attempting to access a character that is outside the bounds of the string results in an IndexOutOfRangeException.
      5. The contents of a string object can be changed after the object is created.

    • Options
    • A. 1, 3
    • B. 3, 5
    • C. 2, 4
    • D. 1, 2, 4
    • Discuss
    • 9. Which of the following snippets are the correct way to convert a Single into a String?

      1. Single f = 9.8f; 
        String s;
        s = (String) (f);
      2. Single f = 9.8f; 
        String s;
        s = Convert.ToString(f);
      3. Single f = 9.8f; 
        String s;
        s = f.ToString();
      4. Single f = 9.8f; 
        String s;
        s = Clnt(f);
      5. Single f = 9.8f; 
        String s;
        s = CString(f);

    • Options
    • A. 1, 2
    • B. 2, 3
    • C. 1, 3, 5
    • D. 2, 4
    • Discuss
    • 10. Which of the following statement is correct about a String in C#.NET?

    • Options
    • 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.
    • Discuss


    Comments

    There are no comments.

Enter a new Comment