Arrays And Strings In C Sharp - Study Mode
[#96] What will be the output of the following C# code? static void Main(string[] args)
{
string s1 = "Hello" + " I " + "Love" + " ComputerScience "
Console.WriteLine(s1)
Console.ReadLine()
}
Correct Answer
(B) Hello I Love ComputerScience
[#97] What will be the output of the following C# code? String a = "Csharp"
String b = "CSHARP"
int c
c = a.CompareTo(b)
Console.WriteLine(c)
Correct Answer
(D) -1
[#98] Complete the following C# code with "foreach condition". int[][]a = new int[2][]
a[0] = new int[3]{3, 4, 2}
a[1] = new int[2]{8, 5}
foreach( int[]i in a)
{
/* add for loop */
console.write( j+ " ")
console.writeline()
}
Correct Answer
(D) foreach (int j in i)
[#99] What will be the output of the following C# code? static void Main(string[] args)
{
Program p = new Program()
p.display(2, 3, 8)
int []a = { 2, 56, 78, 66 }
Console.WriteLine("example of array")
Console.WriteLine("elements added are")
p.display(a)
Console.ReadLine()
}
public void display(params int[] b)
{
foreach (int i in b)
{
Console.WriteLine("ARRAY IS HAVING:{0}", i)
}
}
Correct Answer
(D) Code runs successfully and prints given on console
[#100] What will be the output of the following C# code? static void main(string[] args)
{
int []arr = new int[]{ 1, 2, 3, 4, 5}
fun (ref arr)
for (int i = 0
i < arr.Length
i++)
Console.WriteLine( arr[i] + " ")
}
static void fun(ref int[]a)
{
a = new int[6]
a[3] = 32
a[1] = 24
}
Correct Answer
(B) 0, 24, 0, 32, 0, 0