1.  What is output of the given set of Code ?
class Program
{
static void Main(string[] args)
{
String []chars = {‘’z’’, ‘’x’’, ‘’y’’, ‘’z’’, ‘’y’’};
for (int i = 0; i < chars.Length; ++i)
for (int j = i + 1; j < chars.Length; ++j)
if(chars[i].CompareTo(chars[j]) == 0)
Console.WriteLine(chars[j]);
Console.ReadLine();
}
}


zx
xy
zy
yz


Answer

 Option

compareTo() function returns zero when both the strings are equal, it returns a value less than zero if the invoking string is less than the other string being compared and value greater than zero when invoking string is greater than the string compared To.4

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

2.  What is the value returned by function compareTo() if the invoking string is less than the string compared ?


zero
value less than zero
value greater than zero
None of the mentioned


Answer

 Option

compareTo() function returns zero when both the strings are equal, it returns a value less than zero if the invoking string is less than the other string being compared and value greater than zero when invoking string is greater than the string compared to.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

3.  What does the term ‘immutable’ means in term of string objects ?


We can modify characters included in the string
We cannot modify characters contained in the string
We cannot perform various operation of comparison,inserting,appending etc
none of the mentioned


Answer

 Option

String objects are ‘immutable’ means we cannot modify the characters contained in string. Also operation on string produce a modified version of string rather then modifying characters of string.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

4.  What is the String in C# meant for ?


Variable
Character Array
Object
Class


Answer

 Option

C# Supports a predefined reference type known as string.When we declare a string using string type we are declaring the object to be of type “System.String”.

Workspace

Report
Mail id: Report Error:

Answer Workspace Report

5.  Correct way to convert a string to uppercase using string class method() ?


Upper()
ToUpper()
Object.ToUpper()
None of the mentioned


Answer

 Option

string s1 = “Hello I Love Csharp “; Console.WriteLine(s1.ToUpper());

Workspace

Report
Mail id: Report Error:

Answer Workspace Report