0% found this document useful (0 votes)
51 views

C# MCQ

Uploaded by

Rama Subramanian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

C# MCQ

Uploaded by

Rama Subramanian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

PSN COLLEGE OF ENGINEERING AND TECHNOLOGY (AUTONOMOUS)

Melathediyoor, Tirunelveli – 627 152


(Approved by AICTE and Recognized by UGC Section 2f &12B)
(Accredited by NAAC A+, Affiliated to Anna University)
An ISO 9001:2015 Certified Institution
Web site: www.psncet.ac.in Email.ID:[email protected]
Phone. No: 04634-279009

MULTIPLE CHOICE QUESTIONS

Year / Semester / Dept. : IV Year / VII / CSE


Subject Code and Subject Name: 503021 and C# and .NET Programming

1. C# is a programming language, developed by .


A. Oracle
B. Microsoft
C. GNU project
D. Google

2. C# runs on the .
A. .NET Framework
B. Java Virtual Machine
C. Both A. and B.
D. None of the above

3. C# programming language is used to develop -


A. Web apps
B. Desktop apps
C. Mobiles apps
D. All of the above

4. Is C# an object-oriented programming language?


A. Yes
B. No

5. Is C++ an alias of C#?


A. Yes
B. No
6. What is the extension of a C# language file?
A. .c
B. .cpp
C. .cs
D. .csp

7. Who is the founder of C# programming language?


A. Anders Hejlsberg
B. Douglas Crockford
C. RasmusLerdorf
D. Brendan Eich

1|P a g e
Department of Computer Science and Engineering
8. CLR stands for .
A. Common Type System
B. Common Language Specification
C. Common Language Runtime
D. Java Virtual Machine

9. Net CLR is equivalent to?


A. Common Type System
B. Common Language Specification
C. Common Language Runtime
D. Java Virtual Machine

10. What does the CLR in C# do?


A. Manages the execution of Webpages programs
B. Manages the parsing of the various types
C. Manages the execution of .NET programs
D. All of the above

11. Which symbols are used to mark the beginning and end of a code block?
A. Square brackets []
B. Curly braces {}
C. Round brackets ()
D. Double-quotes ""

12. Every C# statement is terminated by .


A. Colon (:)
B. Semicolon (;)
C. Comma (,)
D. Dot (.)
13. In C#, a single-line comment starts with .
A. Two forward slashes (//)
B. Two backward slashes (\\)
C. A hash character (#)
D. A dollar character ($)

14. What is the correct syntax to declare a variable in C#?


A. type variableName = value;
B. type variableName;
C. variableName as type = value;
D. Both A. and B.

15. Which C# keyword is used to define a constant?


A. define
B. fixed
C. constant
D. const

16. What is the correct syntax to define a C# constant?


A. const type constant_name;
B. const type constant_name = value;
C. constconstant_name as type;
D. constconstant_name as type = value;

2|P a g e
Department of Computer Science and Engineering
17. Which is the correct order for implicit type conversion to convert a smaller to a larger type in C#?
A. char ->int -> long -> float -> double
B. bool -> char ->int -> long -> float -> double
C. char ->int -> float -> long -> double
D. bool -> char ->int -> long -> double -> float

18. Which is the correct order for explicit type conversion to convert a larger to a smaller type in C#?
A. double -> float -> long ->int -> char -> bool
B. double -> float -> long ->int -> char
C. float -> double -> long ->int -> char
D. float -> double -> long ->int -> char -> bool

19. What will be the output of the following C# code?

usingSystem;

namespaceMyApplication {
classProgram {
staticvoidMain(string[] args) {
bool x = true;
Console.Write(Convert.ToString(x));
}
}
}

A. True
B. true
C. False
D. false

20. What will be the output of the following C# code?

usingSystem;

namespaceMyApplication {
classProgram {
staticvoidMain(string[] args) {
double x = 10.25;
Console.Write(Convert.ToInt32(x));
}
}
}

A. 10.30
B. 10.25
C. 10
D. Error

21. What is 'Console' in C#?


A. Class
B. Object
C. Method
D. Structure

22. What will be the output of the following C# code, if the input is 123?

3|P a g e
Department of Computer Science and Engineering
usingSystem;

namespaceMyApplication {
classProgram {
staticvoidMain(string[] args) {
Console.WriteLine("Enter a number:");
intnum = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Given number is: " + num);
}
}
}

A. Given number is:123


B. Given number is: 123
C. Given number is: "123"
D. Error

23. Which is/are the correct method(s) to input a float value in C#?
A. Parse(Console.ReadLine())
B. ToSingle(Console.ReadLine())
C. ToFloat(Console.ReadLine());
D. Both A and B
E. Both A and C

24. What will be the output of the following C# code?

usingSystem;

namespaceMyApplication {
classProgram {
staticvoidMain(string[] args) {
int a = 10, b = 20;
Console.WriteLine("{0},{0}", a, b);
}
}
}

A. 10,10
B. 10,20
C. 20,20
D. Error

25. What will be the output of the following C# code?

usingSystem;

classProgram {
staticvoidMain(string[] args) {
inti = 2;
int j = 10 / 4;

if (i == j) {
Console.WriteLine("True");
} else {
Console.WriteLine("False");
}
}
}

A. True
4|P a g e
Department of Computer Science and Engineering
B. False
C. Error
D. None

26. What will be the output of the following C# code?

usingSystem;

classProgram {
staticvoidMain(string[] args) {
Console.WriteLine(true ^ true);
}
}

A. True
B. False
C. Error
D. None
27. What will be the output of the following C# code?
usingSystem;
classProgram {
static void Main(string[] args)
{
int i = 100;
do {
Console.Write(i + " ");
++i;
} while (i<= 50);
}
A. Error
B. 100 101 102 ... Infinite
C. 101
D. 100

28. What will be the output of the following C# code?

usingSystem;
classProgram {
publicstaticvoidMain() {
inti = 10;
Console.WriteLine(i++);
}
}

A. 10
B. 11
C. 12
D. Error

29. Which is the correct for() statement to run an infinite loop?


A. for(;;)
B. for(;;);
C. for(;;)
D. for(1;1;1)
30. What is the use of 'throw' statement in C#?

5|P a g e
Department of Computer Science and Engineering
A. to return from the calling functions to called function
B. to throw an exception manually during the execution of the program
C. to return from the switch statement
D. None of the above

31. Which C# keyword is used to coming out from the loop?


A. break
B. continue
C. Both A and B
D. None of the above

32. What is String in C# meant for?


A. A variable
B. A Class
C. An Array
D. An object

33. Which is the base class of the String() Constructor?


A. String
B. System.IO.String
C. System.Strings
D. System.String

34. Which is the correct method to convert given string in uppercase?


A. Upper()
B. ToUpper()
C. Upr()
D. ToUpr()

35. What is String.Length in C#?


A. Property
B. Method
C. Constructor
D. Both A and B

36. What will be the output of the following C# code?

usingSystem;

classProgram {
staticvoidMain(string[] args) {
String s1 = "Hello";
String s2 = "IncludeHelp";
String s3 = s1;
Console.WriteLine(s1.Equals(s3) + " " + s2.CompareTo(s1));
}
}

A. Error
B. True True
C. True False
D. True 1

37. What will be the output of the following C# code?


6|P a g e
Department of Computer Science and Engineering
usingSystem;

classProgram {
staticvoidMain(string[] args) {
String str = "Hello";
Console.WriteLine(str.Length);

}
}

A. 5
B. 6
C. 7
D. 4

38. What will be the output of the following C# code?

usingSystem;

classProgram {
staticvoidMain(string[] args) {
String str = "Hello";
Console.WriteLine(str.IndexOf('h'));
}
}

A. 0
B. 1
C. -1
D. Error

39. What will be the output of the following C# code?

usingSystem;

namespaceMyApplication {
classProgram {
staticvoidMain(string[] args) {
string[] mobiles = { "iPhone", "Samsung", "Vivo"};
Console.WriteLine(mobiles);
}
}
}

A. "iPhone", "Samsung", "Vivo"


B. {"iPhone", "Samsung", "Vivo"}
C. string[]
D. System.String[]

40. What will be the output of the following C# code?

7|P a g e
Department of Computer Science and Engineering
usingSystem;

namespaceMyApplication {
classProgram {
staticvoidMain(string[] args) {
string[] mobiles = {"iPhone", "Samsung", "Vivo"};
Console.WriteLine(mobiles[-1]);
}
}
}

A. None
B. Warning
C. Exception
D. System.String[]
41. Which array property is used to get the total number of elements in C#?

A. Len
B. Length
C. Elements
D. MaxLen

42. Which array method is used to sort an array alphabetically or in an ascending order in C#?

A. sort()
B. sorting()
C. Sort()
D. Sorting()

43. What will be the output of the following C# code?

usingSystem;

namespaceMyApplication {
classProgram {
staticvoidMain(string[] args) {
int[,] ARR = {{1,2},{3,4}};
Console.WriteLine(ARR.GetLength(0)+","+ARR.GetLength(1));
}
}
}

A. 4,4
B. 2,2
C. Compilation Error
D. Runtime Error

44. Which is the correct way to declare an object of the class in C#?

A. Class_NameObject_Name = new Class_Name();


B. Class_NameObject_Name;
C. new Object_Name as Class_Name();
D. Both A and B

45. Which operator is used to access variables/fields inside a class in C#?


A. Arrow Operator (->)

8|P a g e
Department of Computer Science and Engineering
B. Dot Operator (.)
C. Greater Than (>)
D. Dot and Greater Than (.>)

46. Which is not a type of constructor in C#?

A. Static Constructor
B. Private Constructor
C. Body Constructor
D. Parameterized Constructor
47. How many types of access modifiers in C#?

A. 2
B. 3
C. 4
D. 5

48. The internal access modifier is used for .

A. Types and type members


B. Defining a field that can be accessed in all classes
C. Defining a field that can be accessed in inherited classes
D. All of the above

49. Which C# concept has the capability of an object to take number of different forms and hence
display behaviour as accordingly?

A. Polymorphism
B. Encapsulation
C. Abstraction
D. None of the above

50. What will be the output of the following C# code?

1. staticvoid Main(string[]args)
2. {
3. int a =5;
4. int s =0, c =0;
5. Mul(a, ref s, ref c);
6. Console.WriteLine(s +"t "+c);
7. Console.ReadLine();
8. }
9. staticvoidMul(int x, refintss, refint cc)
10. {
11. ss= x * x;
12. cc = x * x * x;
13. }
a) 125 25
b) 25 125
c) Compile time error
d) 0 0

9|P a g e
Department of Computer Science and Engineering
51. Which of the following statements are correct about functions?
a) C# allows a function to have arguments with default values
b) Redefining a method parameter in the method’s body causes an exception
c) C# allows function to have arguments with default values
d) Omitting the return type in method definition results into exception
52. What will be the output of the following C# code?

staticvoid Main(string[]args)
{
Mul();
m();
Console.ReadLine();
}
. staticvoidMul()
{
Console.WriteLine("4");
}
staticvoid m()
{
Console.WriteLine("3");
Mul();
}

a) 4 3 3
b) 4 4 3
c) 4 3 4
d) 3 4 4

53. What will be the output of the following C# code?

1. staticvoid Main(string[]args)
2. {
3. m();
4. Console.ReadLine();
5. }
6. staticvoid m()
7. {
8. Console.WriteLine("HI");
9. m();
10. }
a) HI HIHI
b) HI
c) Stack overflow exception
d) Compile time error

54. How many values does a function return?


a) 0
b) 2
c) 1
d) any number of values

10 | P a g e
Department of Computer Science and Engineering
55. What will be the output of the following C# code?

1. staticvoid Main(string[]args)
2. {
3. int y =3;
4. y++;
5. if(y <=5)
6. {
7. Console.WriteLine("hi");
8. Main(args);
9. }
10. Console.ReadLine();
11. }

a) hihi
b) hi
c) Stack overflow exception
d) None of the mentioned

57. What will be the output of the following C# code?


public static void Main(string[ ] args) {
p();
void p(){
Console.WriteLine("hi");}
}

a) Compile time error


b) hi
c) hi infinite times
d) None of the mentioned

58. Number of constructors a class can define is?


a) 1
b) 2
c) Any number
d) None of the mentioned

59. Correct way to define object of sample class in which C# code will work correctly is:

Class abc
{
int i;
float k;
public abc(int ii, float kk)
{
i= ii;
k =kk;
} }
a) abc s1 = new abc(1);
b) abc s1 = new abc();
c) abc s2 = new abc(1.4f);
d) abc s2 = new abc(1, 1.4f);

11 | P a g e
Department of Computer Science and Engineering
60. Correct statement about constructors in C#.NET is?
a) Constructors can be overloaded
b) Constructors are never called explicitly
c) Constructors have same name as name of the class
d) All of the mentioned

61. What is the return type of constructors?


a) int
b) float
c) void
d) none of the mentioned

62. Which method has the same name as that of its class?
a) delete
b) class
c) constructor
d) none of the mentioned

63. Which operator among the following signifies the destructor operator?
a) ::
b) :
c) ~
d) &

64. Name a method which has the same name as that of class and which is used to destroy objects
also called automatically when application is finally on process of being getting terminated.
a) Constructor
b) Finalize()
c) Destructor
d) End

65. Which of the following statements are correct?


a) There is one garbage collector per program running in memory
b) There is one common garbage collector for all programs
c) To garbage collect an object set all references to it as null
d) Both There is one common garbage collector for all programs & To garbage collect an object set allreferences to it as
null

66. Select wrong statement about destructor in C#?


a) A class can have one destructor only
b) Destructors cannot be inherited or overloaded
c) Destructors can have modifiers or parameters
d) All of the mentioned

67. What is the return type of destructor?


a) int
b) void
c) float
d) none of the mentioned

12 | P a g e
Department of Computer Science and Engineering
68. What will be the output of the following C# code?

class box{
publicint volume;
int width;
int height;
int length;
public box (int w, int h, int l)
{
this.width= w;
this.height= h;
this.length= l;
}

. ~ box()
{
volume =this.width*this.length*this.height;
console.writeline(volume);
}
}
class Program
{
public static void Main(string[]args)
{
box b =new box(4, 5, 9);
Console.ReadLine();
}
}
a) 0
b) Code executes successfully but prints nothing
c) Compile time error
d) 180

69. Choose the correct statement among the followings?


a) Indexers are location indicators
b) Indexers are used to access class objects
c) Indexer is a form of property and works in the same way as a property
d) All of the mentioned

70. Choose the operator/operators which is/are not used to access the [] operator in indexers?
a) get
b) set
c) access
d) all of the mentioned

71. Choose the correct statement among the following?


a) A property can be a static member whereas an indexer is always an instance member
b) A get accessor of a property corresponds to a method with no parameters whereas get accessor of an
indexer corresponds to a method with the same formal parameters lists as the indexer
c) It is an error for indexer to declare a local variable with the same name as indexer parameters
d) All of the mentioned

13 | P a g e
Department of Computer Science and Engineering
72. Which among the following are the advantages of using indexers?
a) To use collection of items at a large scale we make use of indexers as they utilize objects of class that
represent the collection as an array
b) Indexers are also convenient as they can also make use of different types of indexers like int, string etc
c) An indexer allows an object to be indexed such as an array
d) All of the mentioned

73. Choose the correct option among the following indexers which correctly allows to index in same
way as an array?
a) A class
b) An interface
c) A function
d) A property

74. Where the properties can be declared?


a) Class
b) Struct
c) Interface
d) All of the mentioned
75. Select the modifiers which can be used with the properties?
a) Private
b) Public
c) Protected Internal
d) All of the mentioned

76. Consider a class maths and we had a property called a sum.b is a reference to a maths object and
we want the statement b.sum = 10 to fail. Which of the following is the correct solution to ensure
this functionality?
a) Declare sum property with both get and set accessors
b) Declare sum property with only get accessor
c) Declare sum property with get, set and normal accessors
d) None of the mentioned

77. Consider a class maths and we had a property called as sum.b which is the reference to a maths
object and we want the statement Console.WriteLine(b.sum)to fail. Which among the following is
the correct solution to ensure this functionality?
a) Declares sum property with only get accessor
b) Declares sum property with only set accessor
c) Declares sum property with both set and get accessor
d) Declares sum property with both set, get and normal accessor

78. Which among the following is NOT an exception?


a) Stack Overflow
b) Arithmetic Overflow or underflow
c) Incorrect Arithmetic Expression
d) All of the mentioned

79. Which among the following is considered as .NET Exception class?


a) Exception
b) StackUnderflow Exception
c) File bound Exception
d) All of the mentioned

14 | P a g e
Department of Computer Science and Engineering
80. Select the correct statement about an Exception?
a) It occurs during loading of program
b) It occurs during Just-In-Time compilation
c) It occurs at run time
d) All of the mentioned

81. Which of these keywords is not a part of exception handling?


a) try
b) finally
c) thrown
d) catch

82. Which of these keywords must be used to monitor exceptions?


a) try
b) finally
c) throw
d) catch

83. Which of these keywords is used to manually throw an exception?


a) try
b) finally
c) throw
d) catch

84. What will be the output of the following C# code?


static void Main(string[] args)
{
try
{
Console.WriteLine("csharp"+" "+1/Convert.ToInt32(0)); }
catch(ArithmeticException e){
Console.WriteLine("Java");
}
Console.ReadLine();
}

a) csharp
b) java
c) run time error
d) csharp 0

85. Which of the following is the wrong statement about exception handling in C#.NET?
a) finally clause is used to perform cleanup operations of closing network and database connections
b) a program can contain multiple finally clauses
c) the statement in final clause will get executed no matter whether an exception occurs or not
d) all of the mentioned

15 | P a g e
Department of Computer Science and Engineering
86. What will be the output of the following C# code?

1. class Program
2. {
3. staticvoid Main(string[]args)
4. {
5. try
6. {
7. Console.WriteLine("csharp"+" "+1/0);
8. }
9. finally
10. {
11. Console.WriteLine("Java");
12. }
13. Console.ReadLine();
14. }
15. }
a) csharp 0
b) Run time Exception generation
c) Compile time error
d) Java

87. What will be the output of the following C# code?

1. {
2. try
3. {
4. int[]a ={1, 2, 3, 4, 5};
5. for(inti=0;i<5;++i)
6. Console.WriteLine(a[i]);
7. int x =(1/ Convert.ToInt32(0));
8. }
9. catch(IndexOutOfRangeException e)
10. {
11. Console.WriteLine("A");
12. }
13. catch(ArithmeticException e)
14. {
15. Console.WriteLine("B");
16. }
17. Console.ReadLine();
18. }
a) 1234
b) 12345
c) Run time error
d) 12345B

16 | P a g e
Department of Computer Science and Engineering
88. What will be the output of the following C# code?

1. {
2. try
3. {
4. int[]a ={1, 2, 3, 4, 5};
5. for(inti=0;i<7;++i)
6. Console.WriteLine(a[i]);
7. }
8. catch(IndexOutOfRangeException e)
9. {
10. Console.WriteLine("0");
11. }
12. Console.ReadLine();
13. }
a) 12345
b) 123450
c) 1234500
d) Compile time error

89. What will be the output of the following C# code snippet?

1. {
2. try
3. {
4. int a, b;
5. b =0;
6. a =10/ b;
7. Console.WriteLine("A");
8. }
9. catch(ArithmeticException e)
10. {
11. Console.WriteLine("B");
12. }
13. Console.ReadLine();
14. }
a) A
b) B
c) Compile time error
d) Run time error

90. What will be the output of the following C# code?

1. {
2. try
3. {
4. inti, sum;
5. sum =10;

17 | P a g e
Department of Computer Science and Engineering
6. for(i=-1;i<3;++i)
7. {
8. sum =(sum /i);
9. Console.WriteLine(i);
10. }
11. }
12. catch(ArithmeticException e)
13. {
14. Console.WriteLine("0");
15. }
16. Console.ReadLine();
17. }
a) -1
b) 0
c) -1 0
d) -1 0 -1

91. What will be the output of the following C# code snippet?

1. {
2. try
3. {
4. int a, b;
5. b =0;
6. a =5/ b;
7. Console.WriteLine("A");
8. }
9. catch(ArithmeticException e)
10. {
11. Console.WriteLine("B");
12. }
13. finally
14. {
15. Console.WriteLine("C");
16. }
17. Console.ReadLine();
18. }
a) A
b) B
c) B C
d) Run time error

92. When is no exception thrown at runtime then who will catch it?
a) CLR
b) Operating System
c) Loader
d) Compiler

18 | P a g e
Department of Computer Science and Engineering
93. What will be the output of the following C# code?

1. publicstaticvoid Main(string[]args)
2. {
3. try
4. {
5. int a, b, c =5;
6. b =0;
7. a = c / b;
8. Console.WriteLine("A");
9. }
10. catch(ArithmeticException e)
11. {
12. int c =5;
13. inti=10;
14. int z =2* c -i;
15. Console.WriteLine("B");
16. Console.WriteLine(z);
17. }
18. Console.ReadLine();
19. }
a) Compile time error
b) Run time error
c) B 0
d) B

94. Choose the correct statement which makes exception handling work in C#.NET?
a) .Net runtime makes search for the exception handler where exception occurs
b) If no exception is matched, exception handler goes up the stack and hence finds the match there
c) If no match is found at the highest level of stack call, then unhandledException is generated and hence
termination of program occurs
d) All of the mentioned

95. Which of these clauses will be executed even if no exceptions are found?
a) throws
b) finally
c) throw
d) catch

96. Which of these exceptions handles the divide by zero error?


a) ArithmeticException
b) MathException
c) IllegalAccessException
d) IllegarException

19 | P a g e
Department of Computer Science and Engineering
97. What will be the output of the following C# code snippet?

1. class program
2. {
3. publicstaticvoid Main(string[]args)
4. {
5. try
6. {
7. thrownewNullReferenceException("C");
8. Console.WriteLine("A");
9. }
10. catch(ArithmeticException e)
11. {
12. Console.WriteLine("B");
13. }
14. Console.ReadLine();
15. }
16. }
a) A
b) B
c) Compile time error
d) Runtime error

98. What will be the output of the following C# code snippet?

1. class Program
2. {
3. publicstaticvoid Main(string[]args)
4. {
5. try
6. {
7. int a =1;
8. int b =10/ a;
9. try
10. {
11. if(a ==1)
12. a = a / a - a;
13. if(a ==2)
14. {
15. int[] c ={1};
16. c[8]=9;
17. }
18. }
19. finally
20. {
21. Console.WriteLine("A");
22. }
23. }
24. catch(IndexOutOfRangeException e)
25. {
26. Console.WriteLine("B");

20 | P a g e
Department of Computer Science and Engineering
27. }
28. Console.ReadLine();
29. }
30. }
a) A
b) B
c) AB
d) BA

99. What will be the output of the following C# code snippet?

1. class Program
2. {
3. publicstaticvoid Main(string[]args)
4. {
5. try
6. {
7. int a =args.Length;
8. int b =10/ a;
9. Console.WriteLine(a);
10. try
11. {
12. if(a ==1)
13. a = a / a - a;
14. if(a ==2)
15. {
16. int[] c ={1};
17. c[8]=9;
18. }
19. }
20. catch(IndexOutOfRangeException e)
21. {
22. Console.WriteLine("TypeA");
23. }
24. }
25. catch(ArithmeticException e)
26. {
27. Console.WriteLine("TypeB");
28. }
29. Console.ReadLine();
30. }
31. }
a) TypeA
b) TypeB
c) 0TypeA
d) Compile time error

21 | P a g e
Department of Computer Science and Engineering
100. Which of the following keywords is used by the calling function to guard against the exception
that is thrown by called function?
a) try
b) throw
c) throws
d) catch

101. Which of these classes is related to all the exceptions that are explicitly thrown?
a) Error
b) Exception
c) Throwable
d) Throw

102. Which of the classes provide the operation of reading from and writing to the console in
C#.NET?
a) System.Array
b) System.Output
c) System.ReadLine
d) System.Console

103. Which of the given stream methods provide access to the input console in C#.NET?
a) Console.Out
b) Console.Error
c) Console.In
d) All of the mentioned

104. The number of input methods defined by the stream method Console.In in C#.NET is?
a) 4
b) 3
c) 2
d) 1

105. Select the correct methodS provided by Console.In?


a) Read(), ReadLine()
b) ReadKey(), ReadLine()
c) Read(), ReadLine(), ReadKey()
d) ReadKey(), ReadLine()

106. Choose the output returned when read() reads the character from the console?
a) String
b) Char
c) Integer
d) Boolean

107. Choose the output returned when an error condition is generated while read() reads from the
console.
a) False
b) 0
c) -1
d) All of the mentioned

22 | P a g e
Department of Computer Science and Engineering
108. What will be the output of the following C# code?

1. staticvoid Main(string[]args)
2. {
3. Console.WriteLine("This is a Console Application:");
4. Console.Write("Please enter your lucky number:");
5. string val1 =Console.ReadLine();
6. int val2 =System.Convert.ToInt32(val1, 10);
7. val2 = val2 * val2;
8. Console.WriteLine("square of number is:"+val2);
9. Console.Read();
10. }
a) Compile time error
b) Runs successfully does not print anything
c) Runs successfully, ask for input and hence displays the result
d) Syntax Error

109. Select the objects of the class TextWriter which is/are not used to perform the write operations
to the console?
a) Write()
b) WriteLine()
c) WriteError()
d) All of the mentioned

110. Choose the correct statement about the WriteLine()?


a) Can display one or more value to the screen
b) Adds a newline character at the end of the each new output
c) Allows to output data in as many different formats
d) All of the mentioned

111. What will be the output of the following C# code snippet?

1. staticvoid Main(string[]args)
2. {
3. StringBuildersb=newStringBuilder("hello world");
4. sb.Insert(6, "good");
5. Console.WriteLine(sb);
6. Console.ReadLine();
7. }
a) hello 6world
b) hello good world
c) hello goodworld
d) hello good world

23 | P a g e
Department of Computer Science and Engineering
112. What will be the output of the following C# code snippet?

1. staticvoid Main(string[]args)
2. {
3. StringBuildersb=newStringBuilder("hello world");
4. sb.Insert(6, "good");
5. Console.WriteLine(sb);
6. Console.ReadLine();
7. }
a) hello 6world
b) hello good world
c) hello goodworld
d) hello good world

113. Which of these classes is used to create an object whose character sequence is mutable?
a) String()
b) StringBuilder()
c) String() &StringBuilder()
d) None of the mentioned

114. Select the method used to write single byte to a file?


a) Write()
b) Wrteline()
c) WriteByte()
d) All of the mentioned

115. The ‘ref’ keyword can be used with which among the following?
a) Static function/subroutine
b) Static data
c) Instance function/subroutine
d) All of the mentioned

116. Suppose a Generic class called as SortObjects is to be made capable of sorting objects of any
type(integer, single, byte etc). Then, which of the following programming constructs is able to
implement the comparison function?
a) interface
b) encapsulation
c) delegate
d) attribute

117. To generate a simple notification for an object in runtime, the programming construct to be
used for implementing this idea?
a) namespace
b) interface
c) delegate
d) attribute

24 | P a g e
Department of Computer Science and Engineering
118. Which among the following is the correct statement about delegate declaration?

delegate void del(inti);

a) on declaring the delegate, a class called del is created


b) the del class is derived from the MulticastDelegate class
c) the del class will contain a one argument constructor and an invoke() method
d) all of the mentioned

119. Which among the following differentiates a delegate in C#.NET from a conventional function
pointer in other languages?
a) delegates in C#.NET represent a new type in the Common Type System
b) delegates allows static as well as instance methods to be invoked
c) delegates are type safe and secure
d) none of the mentioned

120. Which of the following statements is correct about a delegate?


a) inheritance is a prerequisite for using delegates
b) delegates are not type safe
c) delegates provides wrappers for function pointers
d) none of the mentioned

121. What will be the output of the following C# code snippet?

1. {
2. delegatevoid A(refstringstr);
3. class sample
4. {
5. publicstaticvoid fun(refstring a)
6. {
7. a =a.Substring(7, a.Length-7);
8. }
9. }
10. class Program
11. {
12. staticvoid Main(string[]args)
13. {
14. A str1;
15. stringstr="Test Your C#.net skills";
16. str1 = sample.fun;
17. str1(refstr);
18. Console.WriteLine(str);
19. }
20. }
21. }
a) Test Your
b) ur C#.NET
c) ur C#.NET Skills
d) None of the mentioned

25 | P a g e
Department of Computer Science and Engineering
122. What will be the output of the following C# code snippet?
1. {
2. delegatestring F(stringstr);
3. class sample4. {
5. publicstaticstring fun(string a)6. {
7. returna.Replace(',''-');8. }
9. }
10. class Program
11. {
12. staticvoid Main(string[]args)
13. {
14. F str1 =new F(sample.fun);
15. stringstr= str1("Test Your c#.NET skills");
16. Console.WriteLine(str);
17. }
18. }
19. }

a) Test Your
b) Test-Your-C#.NET-Skills
c) ur C#.NET Skills
d) None of the mentioned

123. Which of the following are the correct statements about delegates?
a) Delegates can be used to implement callback notification
b) Delegates permit execution of a method on a secondary thread in an asynchronous manner
c) Delegate is a user defined type
d) All of the mentioned

124. Incorrect statements about delegates are?


a) Delegates are reference types
b) Delegates are object oriented
c) Delegates are type safe
d) Only one method can be called using a delegate

125. Select the modifiers which control the accessibility of the delegate?
a) new
b) protected
c) public
d) all of the mentioned

126. The process of defining two or more methods within the same class that have same name but
different parameters list?
a) Method overloading
b) Method overriding
c) Encapsulation
d) None of the mentioned

26 | P a g e
Department of Computer Science and Engineering
127. Which of these can be overloaded?
a) Constructors
b) Methods
c) Both Constructors & Methods
d) None of the mentioned

128. What will be the output of the following C# code?

1. class maths
2. {
3. publicint x;
4. publicdouble y;
5. publicintadd(int a, int b)
6. {
7. x = a + b;
8. return x;
9. }
10. publicintadd(double c, double d)
11. {
12. y = c + d;
13. return(int)y;
14. }
15. public maths()
16. {
17. this.x=0;
18. this.y=0;
19. }
20. }
21. class Program
22. {
23. staticvoid Main(string[]args)
24. {
25. maths obj=new maths();
26. int a =4;
27. double b =3.5;
28. obj.add(a, a);
29. obj.add(b, b);
30. Console.WriteLine(obj.x+" "+obj.y);
31. Console.ReadLine();
32. }
33. }
a) 4, 3.5
b) 8, 0
c) 7.5, 8
d) 8, 7

129. What is the process of defining a method in terms of itself, that is a method that calls itself?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Recursion

27 | P a g e
Department of Computer Science and Engineering
130. What will be the output of the following C# code?

1. class maths
2. {
3. publicint fun(int k, int y)
4. {
5. return k + y;
6. }
7. publicint fun1(int t, float z)
8. {
9. return(t+(int)z);
10. }
11. }
12. class Program
13. {
14. staticvoid Main(string[]args)
15. {
16. maths obj=new maths();
17. inti;
18. int b =90;
19. int c =100;
20. int d =12;
21. float l = 14.78f;
22. i=obj.fun(b, c);
23. Console.WriteLine(i);
24. int j =(obj.fun1(d, l));
25. Console.WriteLine(j);
26. Console.ReadLine();
27. }
28. }
a) 190, 26.78f
b) 0, 26.78f
c) 190, 26
d) 190, 0

131. Which procedure among the following should be used to implement a ‘Has a’ or a ‘Kind of’
relationship between two entities?
a) Polymorphism
b) Inheritance
c) Templates
d) All of the mentioned

132. The number of levels of inheritance are?


a) 5
b) 4
c) 3
d) 2

28 | P a g e
Department of Computer Science and Engineering
133. In an inheritance chain through which of the following, the base class and its components are
accessible to the derived class?
a) Scope resolution operator(:)
b) Class visibility modifiers (public,private etc.)
c) Dot operator (.)
d) All of the mentioned

134. In Inheritance concept, which of the following members of base class are accessible to derived
class members?
a) static
b) protected
c) private
d) shared

135. Wrong statement about inheritance in C# .NET?


a) In inheritance chain, object construction begins from base class towards derived class
b) Inheritance cannot extend base class functionality
c) A derived class object contains all base class data
d) All of the mentioned

136. Which is the correct way to create an object of the given class abc?
a) Declaring existing class as sealed
b) Declaring existing class as override
c) Declaring existing class as overloads
d) Declaring existing class as shadows

137. Which form of inheritance is not supported directly by C# .NET?


a) Multiple inheritance
b) Multilevel inheritance
c) Single inheritance
d) Hierarchical inheritance

138. If no access modifier for a class is specified, then class accessibility is defined as?
a) public
b) protected
c) private
d) internal

29 | P a g e
Department of Computer Science and Engineering
139. What will be size of the object created depicted by C# code snippet?

1. classbaseclass
2. {
3. privateint a;
4. protectedint b;
5. publicint c;
6. }
7. class derived :baseclass
8. {
9. privateint x;
10. protectedint y;
11. publicint z;
12. }
13. class Program
14. {
15. staticVoid Main(string[]args)
16. {
17. derived a =new derived();
18. }
19. }
a) 20 bytes
b) 12 bytes
c) 16 bytes
d) 24 bytes

140. What will be the output of the following C# code?

1. class sample
2. {
3. public sample()
4. {
5. Console.WriteLine("THIS IS BASE CLASS constructor");
6. }
7. }
8. publicclass sample1 : sample
9. {
10.
11. }
12. class Program
13. {
14. staticvoid Main(string[]args)
15. {
16. sample1 obj=new sample1();
17. Console.ReadLine();
18. }
19. }
a) Code executes successfully prints nothing
b) This is base class constructor
c) Compile time error
d) None of the mentioned

30 | P a g e
Department of Computer Science and Engineering
141. Select the statement which should be added to the current C# code to get the output as 10 20?

1. classbaseclass
2. {
3. protectedint a =20;
4. }
5. class derived :baseclass
6. {
7. int a =10;
8. publicvoid math()
9. {
10. /* add code here */
11. }
12. }
a) Console.writeline( a + ” ” + this.a);
b) Console.Writeline( mybase.a + ” ” + a);
c) console.writeline(a + ” ” + base.a);
d) console.writeline(base.a + ” ” + a);

142. Which of the following cannot be used to declare an interface correctly?


a) Properties
b) Methods
c) Structures
d) Events

143. A class consists of two interfaces with each interface consisting of three methods. The class had
no instance data. Which of the following indicates the correct size of object created from this class?
a) 12 bytes
b) 16 bytes
c) 0 bytes
d) 24 bytes

144. Which of the following statements correctly define about the implementation of interface?
a) The calls to implementation of interface methods are routed through a method table
b) A class which implements an interface can explicitly implement members of that interface
c) One interface can be implemented in another interface
d) None of the mentioned

145. Select the correct statement among the given statements?


a) One class could implement only one interface
b) Properties could be declared inside an interface
c) Interfaces cannot be inherited
d) None of the mentioned

31 | P a g e
Department of Computer Science and Engineering
146. Which of the following is the correct way of implementing an interface addition by class
maths?
a) class maths : addition {}
b) class maths implements addition {}
c) class maths imports addition {}
d) none of the mentioned

147. Access specifiers which can be used for an interface are?


a) Public
b) Protected
c) Private
d) All of the mentioned

148. What will be the Correct statement in the following C# code?


1. interfaceabc
2. {
3. StringFirstName
4. { get;
5. set;
7. }
8. StringLastName
9. { get;
10. set;
12. }
13. void print();
14. void stock();
15. int fun();
16. }

a) Functions should be declared inside an interface


b) It is workable code
c) Properties cannot be declared inside an interface
d) None of the mentioned

149. What will be the Correct statement in the following C# code?


interface a1 {
void f1();
void f2(); }
class a : a1
{
private int i;
void a1.f1()
{}
}
a) Class a could not have an instance data
b) Class a is an abstract class
c) Class a fully implements the interface a1
d) None of the mentioned

150. Choose the wrong statement about ‘INTERFACE’ in C#.NET?


a) An explicitly implemented member could be accessed from an instance of the interface
b) Interfaces are declared public automatically
c) An interface could not contain signature of the indexer
d) None of the mentioned
ANSWERS

1. B 16. B 31. A 46. C 61. D 76. C 91. C 106. C 121. C 136. A


2. A 17. A 32. D 47. C 62. C 77. B 92. A 107. C 122. B 137. A
3. D 18. B 33. D 48. A 63. C 78. C 93. C 108. C 123. D 138. C
4. A 19. A 34. B 49. A 64. C 79. B 94. D 109. C 124. D 139. D
5. B 20. C 35. A 50. B 65. D 80. C 95. B 110. D 125. D 140. C
6. C 21. A 36. D 51. A 66. C 81. C 96. A 111. C 126. A 141. C
7. A 22. B 37. A 52. C 67. D 82. A 97. D 112. C 127. C 142. C
8. C 23. B 38. C 53.C 68. D 83. C 98. A 113. B 128. D 143. D
9. D 24. A 39. D 54. C 69. D 84. B 99. B 114. C 129. D 144. A
10. C 25. A 40. C 55. C 70. C 85. B 100. C 115. A 130. C 145. B
11. B 26. B 41. B 56. A 71. D 86. B 101. C 116. C 131. B 146. A
12. B 27. D 42. C 57. A 72. D 87. D 102. D 117. C 132. B 147. A
13. A 28. A 43. B 58. C 73. A 88. B 103. C 118. D 133. B 148. B
14. D 29. A 44. A 59. D 74. D 89. B 104. B 119. D 134. B 149. B
15. D 30. B 45. B 60. D 75. D 90. C 105. C 120. C 135. B 150. C

You might also like