Delegates And Events In C Sharp - Study Mode
[#66] What will be the output of the following C# code snippet? public class Generic<T>
{
Stack<T> stk = new Stack<T>()
public void push(T obj)
{
stk.Push(obj)
}
public T pop()
{
T obj = stk.Pop()
return obj
}
}
class Program
{
static void Main(string[] args)
{
Generic<string> g = new Generic<string>()
g.push(40)
Console.WriteLine(g.pop())
Console.ReadLine()
}
}
Correct Answer
(C) 40
[#67] Which of the following is the correct way to call the function abc() of the given class in the following C# code? class csharp
{
public int abc(int a)
{
Console.WriteLine("A:Just do it!")
return 0
}
}
Correct Answer
(C) delegate int del(int a)
del d
csharp s = new csharp()
d = new del(ref s.fun)
d(10)
[#68] What will be the output of the following C# code? public class Generic<T>
{
public T Field
}
class Program
{
static void Main(string[] args)
{
Generic<int> g2 = new Generic<int>()
Generic<int> g3 = new Generic<int>()
g2.Field = 8
g3.Field = 4
if (g2.Field % g3.Field == 0)
{
Console.WriteLine("A")
}
else
Console.WriteLine("Prints nothing:")
Console.ReadLine()
}
}
Correct Answer
(B) A
[#69] Which statement is valid for the following C# code snippet? public class Generic<T>
{
public T Field
}
class Program
{
static void Main(string[] args)
{
Generic<String> g = new Generic<String>()
g.Field = "Hi"
Console.WriteLine(g.Field)
}
}
Correct Answer
(D) Code runs successfully
[#70] What will be the output of the following C# code snippet? {
delegate string F(string str)
class sample
{
public static string fun(string a)
{
return a.Replace(',''-')
}
}
class Program
{
static void Main(string[] args)
{
F str1 = new F(sample.fun)
string str = str1("Test Your c#.NET skills")
Console.WriteLine(str)
}
}
}
Correct Answer
(B) Test-Your-C#.NET-Skills