Home » Aptitude Questions and Answers » C# Aptitude Questions and Answers

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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.