C# Strings Aptitude Questions and Answers | Set 3

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

1) Can we create a string object without a new operator?
  1. Yes
  2. No

2) What is the correct output of given code snippets?
static void Main(string[] args)
{
	String str = "sample";

	Console.Write(str.IndexOf('p'));
	Console.Write(str.Length);
}
  1. 46
  2. 36
  3. 37
  4. 47

3) What is the correct output of given code snippets?
static void Main(string[] args)
{
	String str = "sample sample";

	Console.Write(str.IndexOf('p'));
	Console.Write(str.Length);
}
  1. 313
  2. 312
  3. 1012
  4. 1013

4) What is the correct output of given code snippets?
static void Main(string[] args)
{
	String str = "sample sample";

	Console.Write(str.LastIndexOf('p'));
	Console.Write(str.Length);
}
  1. 313
  2. 312
  3. 1012
  4. 1013

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

	if (str1.CompareTo(str2))
		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





Comments and Discussions!

Load comments ↻





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