Arrays And Strings In C Sharp - Study Mode
[#121] What will be the output of the following C# code? static void Main(string[] args)
{
String obj = "hello"
String obj1 = "world"
String obj2 = obj
string s = obj + " " + obj1
Console.WriteLine(s.Substring(6 ,5))
Console.ReadLine()
}
Correct Answer
(C) world
[#122] What will be the output of the following C# code? static void Main(string[] args)
{
int i, j
int[, ] arr = new int[ 3, 3]
for (i = 0
i < 3
++i)
{
for (j = 0
j < 3
++j)
{
arr[i, j] = i * 2 + i * 2
Console.WriteLine(arr[i, j])
}
Console.ReadLine()
}
}
Correct Answer
(A) 0, 0, 0 4, 4, 4 8, 8, 8
[#123] What will be the output of the following C# code? static void Main(string[] args)
{
object[] a = {" 1 ", 4.0f, " harsh "}
fun(a)
Console.ReadLine()
}
static void fun(params object[] b)
{
for (int i = 0
i < b.Length - 1
i++)
Console.WriteLine(b[i] + " ")
}
Correct Answer
(D) 1 4 harsh
[#124] What will be the output of the following C# code? class sum
{
public int x
public int y
public int add (int a, int b)
{
x = a + b
y = x + b
return 0
}
}
class Program
{
static void Main(string[] args)
{
sum obj1 = new sum()
sum obj2 = new sum()
int a = 2
obj1.add(a, a + 1)
obj2.add(5, a)
Console.WriteLine(obj1.x + " " + obj2.y)
Console.ReadLine()
}
}
Correct Answer
(B) 5, 9
[#125] What will be the output of the following C# code? static void Main(string[] args)
{
String c = " Hello Computer "
String a = c.Trim()
Console.WriteLine(""" + s + """)
}
Correct Answer
(C) "Hello Computer"