TATA ELXSI Previous Years Solved Sample Placement Papers
-
What will be the output of the following C# code?
using System; namespace MyApplication { class Program { static void Main(string[] args) { string[] mobiles = {"iPhone", "Samsung", "Vivo"}; Console.WriteLine(mobiles[0] + mobiles[2]); } } }
A: iPhoneVivo
B: iPhone+Vivo
C: Exception
D: iPhone Vivo
Ans: AExplanation:
The statement
mobiles[0] + mobiles[2]
concatenates the 0th and 2nd elements, resulting in"iPhoneVivo"
. -
Which array method is used to sort an array alphabetically or in ascending order in C#?
A: sort()
B: sorting()
C: Sort()
D: Sorting()
Ans: CExplanation:
The
Sort()
method is used to sort an array alphabetically or in ascending order in C#. -
What will be the output of the following C# code?
using System; namespace MyApplication { class Program { static void Main(string[] args) { int[,] ARR = {{1,2},{3,4}}; Console.WriteLine(ARR.GetLength(0) + "," + ARR.GetLength(1)); } } }
A: 4,4
B: 2,2
C: Compilation Error
D: Runtime Error
Ans: BExplanation:
The code prints the dimensions of the 2D array. The first dimension (rows) and the second dimension (columns) both have lengths of 2, so the output is
2,2
. -
Which is the correct syntax to declare an array with 2 rows and 3 columns in C#?
A:
int arr[2][3] = new int[2][3];
B:
int arr[2,3] = new int[2,3];
C:
int[,] arr = new int[2,3];
D:
Ans: Cint [,]arr = new [2,3]int;
Explanation:
The correct way to declare an array with 2 rows and 3 columns in C# is:
int[,] arr = new int[2,3];
-
To declare an array, define the variable type with ___.
A: Square brackets []
B: Curly brackets {}
C: Round brackets ()
D: None of the above
Ans: AExplanation:
To declare an array, define the variable type with square brackets [].
-
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.
-
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.