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

C# Strings Aptitude Questions and Answers | Set 2

C# Strings Aptitude Questions | Set 2: 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;
	String STR3;

	STR2 = STR1;
	STR3 = String.Copy(STR1);

	STR1.Insert(1, "XYZ");

	Console.WriteLine(STR1 + " " + STR2 + " "+STR3);
}
  1. AXYZBC ABC ABC
  2. ABC ABC ABC
  3. AXYZBC AXYZBC ABC
  4. Syntax Error

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

	STR2 = STR1;
	STR3 = String.Copy(STR1);

	STR1 = STR1.Insert(1, "XYZ");

	Console.WriteLine(STR1 + " " + STR2 + " "+STR3);
}
  1. AXYZBC ABC ABC
  2. ABC ABC ABC
  3. AXYZBC AXYZBC ABC
  4. Syntax Error

3) If we will access a character from a string that is outside the string size, then which exception will generate?
  1. ArrayIndexOutOfBoundExcepion
  2. IndexOutOfRangeException
  3. OutOfBoundException
  4. StringException

4) What is the correct way to get a character from string in C#.NET?
static void Main(string[] args)
{
	String s1 = "ABC";
	string s2 = "ABC";

	if(s1==s2)
		Console.WriteLine("S1 and S2 are equal");
	else
		Console.WriteLine("S1 and S2 are not equal");
}
  1. String str="sample"; char ch = str[0];
  2. String str="sample"; char ch = str.getChar(0);
  3. String str="sample"; char ch = str.CharAt(0);
  4. String str="sample"; char ch = str.Char(0);

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

	char ch = str[6];

	Console.WriteLine(ch);
}
  1. E
  2. 'E'
  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.