C# Strings Aptitude Questions and Answers | Set 4

C# Strings Aptitude Questions | Set 4: This section contains aptitude questions and answers on C# Strings.
Submitted by Nidhi, on April 05, 2020

1) What is the correct output of given code snippets?
static void Main(string[] args)
{
    String str1 = "ABC";
    String str2 = "ABC";

    if (str1.CompareTo(str2)==0)
        Console.WriteLine("Both are equal");
    else
        Console.WriteLine("Both are not equal");
}
  1. Both are equal
  2. Both are not equal
  3. Runtime Exception
  4. Syntax Error

2) What is the correct output of given code snippets?
static void Main(string[] args)
{
	String str = "This is a string";
	int i1 = 0;
	int i2 = 0;

	i1 = str.IndexOf('s');
	i2 = str.IndexOf('s', i1 + 1);

	Console.WriteLine(i1 + " " + i2);
}
  1. 3 6
  2. Syntax Error
  3. Runtime Exception
  4. 3 3

3) A string built using the StringBuilder class is Mutable?
  1. Yes
  2. No

4) What is the correct output of given code snippets?
static void Main(string[] args)
{
	String str1 = "Hello ";
	String str2 = "World!";
	String str3;

	str3 = str1.Concat(str2);

	Console.WriteLine(str3);
}
  1. Hello World!
  2. HelloWorld!
  3. Runtime Exception
  4. Syntax Error

5) What is the correct output of given code snippets?
static void Main(string[] args)
{
	String str1 = "Hello ";
	String str2 = "World!";
	String str3;

	str3 = str1+str2;

	Console.WriteLine(str3);
}
  1. Hello World!
  2. HelloWorld!
  3. Runtime Exception
  4. Syntax Error





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.