C# Programming
Description: This Test consists of conceptual questions related to C# language for CS and GATE aspirants. | |
Number of Questions: 15 | |
Created by: Akash Patel | |
Tags: Csharp gate cs Programming |
What will be the output of the following program? using System; class Program { static void Main(string[] args) { String[] s = new String[2]; s[0] = Hello; s[1] = How are you!; foreach (string name: s) { Console.WriteLine( + name); } Console.ReadLine(); } }
What will be the output of the following code? using System;class A { public void DemoA() { Console.WriteLine(Method of class A); } } class B : A { public void DemoB() { Console.WriteLine(Method of class B); } } class Test { static void Main (string[] args) { A a=new B(); a.DemoA(); a.DemoB(); } }
What is the error in the following code, if any? using System;class Demo { private string name; public void print() { Console.WriteLine(nMy name is + name); } public string Name { get { return name; } set { name = value; } } class Program { static void Main(string[] args) { Demo d = new Demo(); Console.Write(Enter your name:t); d.name = Console.ReadLine(); d.print(); Console.ReadLine(); } } }
Which of the following is/are the true statement(s)?
Which of the following is/are the example of boxing in C#?
Which of the following is/are true about the following code? using System;struct A { public int x; public int y; public A(int x, int y) { this.x = x; this.y = y; } public override string ToString() { return ( + x + , + y + ); } } class Test { static void Main() { A a; A b = new A(); a.x = 2; a.y = 4; Console.WriteLine(a={0}, a); Console.WriteLine(b={0}, b); } }
Which of the following is the incorrect declaration of the delegate in C# language?
What is the error in the following code? using System; class Employee { private string[]name = new string[10]; public static string this[int index] { get { return name[index]; } set { name[index] = value; } } } class Test { public static void Main() { Employee emp = new Employee(); emp[0] = Sachin; emp[1] = Rohit; emp[2] = Amit; Console.WriteLine(Emploees are:); for (int i = 0; i < 3;i++) { Console.WriteLine(emp[i]); } Console.ReadLine(); } }
What will be the output of the following code? using System;abstract class Base { protected int number; public abstract int this[int index]; class Child : Base { public override int this[int index] { get { return number; } set { number = value; } } } class Test { public static void Main() { Child obj = new Child(); obj[0] = 20; obj[1]=40 Console.WriteLine(The value is: + obj[0]); } } }
Which of the following is/are the false statement(s)?
Which of the following statement(s) is/are false?
Which of the following code(s) has error?
What is the error in the following code? using System;using System.Collections.Generic;sealed class A { protected void Demo() { Console.WriteLine(The Demo is called); } } class B:A { static void Main(string[] args) { B a = new B(); a.Demo(); } }
What will be the output of the following code? using System;using System.Collections.Generic;class A { public void Demo() { Console.WriteLine(The Demo in base class); } } class B : A { public override void Demo() { Console.WriteLine(The Demo in child class); } } class test { static void Main(string[] args) { B b = new B(); b.Demo(); } }
Which of the following is true about the following code? using System;using System.Collections.Generic;class A { public void Demo() { Console.WriteLine(The Demo in base class); } } class B : A { public new void Demo() { Console.WriteLine(The Demo in child class); } } class test { static void Main(string[] args) { A b = new B(); b.Demo(); } }