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(30);
Console.WriteLine(g.pop());
Console.ReadLine();
}
}
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(30);
Console.WriteLine(g.pop());
Console.ReadLine();
}
}A. 0
B. 30
C. Runtime Error
D. Compile time Error
Answer: Option B
What is the purpose of the System.Net.Sockets.TcpClient class in C#?
A. To handle HTTP requests
B. To create a UDP client
C. To establish a connection to a TCP server
D. To perform DNS resolution
Which namespace in C# is used for networking-related tasks?
A. System.IO
B. System.Data
C. System.Web
D. System.Net
What is the difference between TCP and UDP in networking?
A. TCP provides reliable, connection-oriented communication, while UDP provides unreliable, connectionless communication
B. TCP provides unreliable, connectionless communication, while UDP provides reliable, connection-oriented communication
C. TCP is faster than UDP
D. UDP is more secure than TCP
Which class in C# is used for sending and receiving data over a network stream?
A. System.Net.WebClient
B. System.Net.Sockets.UdpClient
C. System.Net.Sockets.TcpListener
D. System.Net.Sockets.NetworkStream

Join The Discussion