Vidyalelo
C# Programming · Q217

Classes and Objects in C Sharp

Programming · C# Programming · question 217

Q217

What will be the output of the following C# code? class sample public int i; public int[] arr = new int[10]; public void fun(int i, int val) arr[i] = val; class Program static void Main(string[] args) sample s = new sample(); s.i = 10; sample.fun(1, 5); s.fun(1, 5); Console.ReadLine();

A.
sample.fun(1, 5) will not work correctly
Answer
B.
s.i = 10 cannot work as i is 'public'
C.
sample.fun(1, 5) will set value as 5 in arr[1]
D.
s.fun(1, 5) will work correctly

Answer: Option A

Solution

Answer: Option A
No explanation is given for this question Let's Discuss on Board