Mphasis Previous Years Solved Sample Placement Papers
-
What is the use of 'throw' statement in C#?
A: to return from the calling functions to called function
B: to throw an exception manually during the execution of the program
C: to return from the switch statement
D: None of the above
Ans: BExplanation:
The C# throw statement is used to throw an exception manually during the execution of the program.
-
Which C# keyword is used to coming out from the loop?
A: break
B: continue
C: Both A and B
D: None of the above
Ans: AExplanation:
The C# break keyword breaks the execution of the loop and sends the program’s control to the next statement written after the loop.
-
What is String in C# meant for?
A: A variable
B: A Class
C: An Array
D: An object
Ans: DExplanation:
In C#, String is an object of System.String class.
-
Can we use == operator to compare two strings?
A: Yes
B: No
Ans: AExplanation:
Two strings can be compared by using the == Operator.
-
Which is the base class of the String() Constructor?
A: String
B: System.IO.String
C: System.Strings
D: System.String
Ans: DExplanation:
In C#, System.String is a base class for all String related methods, properties, constructors, and operators.
-
Which String class operator is used to determine whether two specified strings have different values?
A: !=
B: !
C: ~
D: ~
Ans: AExplanation:
In C#, the inequality operator (!=) can be used to determine whether two specified strings have different values.
-
Except == operator, which methods can be used to compare two strings?
A: Equals()
B: Compare()
C: Both A and B
D: None of these
Ans: CExplanation:
The Equals() and Compare() methods can also be used to compare two strings in C#.
-
Which is the correct method to convert given string in uppercase?
A: Upper()
B: ToUpper()
C: Upr()
D: ToUpr()
Ans: BExplanation:
The ToUpper() method is used to convert the given string into the uppercase.
using System; class Program { public static void Main() { string str = "includehelp"; Console.WriteLine(str.ToUpper()); } }
-
What is String.Length in C#?
A: Property
B: Method
C: Constructor
D: Both A and B
Ans: AExplanation:
The String.Length is a property of System.String class that is used to get the number of characters in the current String object.
-
What will be the output of the following C# code?
using System; class Program { static void Main(string[] args) { String s1 = "Hello"; String s2 = "IncludeHelp"; String s3 = s1; Console.WriteLine(s1.Equals(s3) + " " + s2.CompareTo(s1)); } }
A: Error
B: True True
C: True False
D: True 1
Ans: DExplanation:
The Equals() method returns a bool value. We assigned
s1
tos3
. Thus, the statements1.Equals(s3)
will return "True". The CompareTo() method returns an int value, ands2.CompareTo(s1)
will return 1 because this instance (s2
) followss1
. -
What will be the output of the following C# code?
using System; class Program { static void Main(string[] args) { String str = "Hello"; Console.WriteLine(str.Length); } }
A: 5
B: 6
C: 7
D: 4
Ans: AExplanation:
The String.Length returns the length of the string. Thus, the output will be 5.
-
What will be the output of the following C# code?
using System; class Program { static void Main(string[] args) { String str = "Hello"; Console.WriteLine(str.IndexOf('h')); } }
A: 0
B: 1
C: -1
D: Error
Ans: CExplanation:
The IndexOf() method returns the index of a given character, and it returns -1 if the given character is not found in the string. Here, we are trying to get the index of 'h' which is not present in the string. Thus, the output will be -1.