C# Strings Aptitude Questions and Answers | Set 1

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

1) There are following statements are given below, which of them are correct about "String" in C#.NET?
  1. In C#.NET, we used the character array to represent a string just like C language.
  2. In C#.NET, String is mutable.
  3. A String is a predefined class in C#, which is used to create strings.
  4. We need to use the System.Array class to create a string.

Options:

  1. Only A
  2. Only D
  3. A and D
  4. Only C

2) In C#, String is a value type?
  1. Yes
  2. No

3) If we have two references for strings like STR1 and STR2. And we want to compare them, and then what is the correct way?
  1. STR1 is STR2
  2. STR1 = STR2
  3. STR1 equal to STR2
  4. STR1.Equals(STR2)

4) What is the correct output of given code snippets?
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. S1 and S2 are equal
  2. S1 and S2 are not equal
  3. Syntax Error
  4. Runtime Exception

5) 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);
	Console.WriteLine(STR1 + " " + STR2 + " "+STR3);
}
  1. ABC ABC
  2. ABC ABC ABC
  3. Syntax Error
  4. Runtime Exception





Comments and Discussions!

Load comments ↻





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