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

C# MCQ

This document contains a quiz on C# and .NET Framework concepts with multiple choice questions and answers. It tests knowledge of topics like data types, operators, classes, methods, and other core C# concepts. The quiz contains 30 questions to test understanding of syntax, programming constructs, and the C# language.

Uploaded by

keerthana.n05731
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

C# MCQ

This document contains a quiz on C# and .NET Framework concepts with multiple choice questions and answers. It tests knowledge of topics like data types, operators, classes, methods, and other core C# concepts. The quiz contains 30 questions to test understanding of syntax, programming constructs, and the C# language.

Uploaded by

keerthana.n05731
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

QUIZ

21CS582 C# and .Net Framework syllabus for CS

1. Which of the following is a reserved keyword in C#?


A - abstract
B - as
C - foreach
D - All of the above.
Answer : D

Explanation

All of the above options are reserved keywords.

2. Which of the following is correct about reference type variables in C#?


A - The reference types do not contain the actual data stored in a variable.
B - They contain a reference to the variables.
C - Example of built-in reference types are: object, dynamic, and string.
D - All of the above.
Answer : D

Explanation

All of the above options are correct.

3. Which of the following converts a type to a double type in C#?


A - ToDecimal
B - ToDouble
C - ToInt16
D - ToInt32
Answer : B

Explanation

ToDouble() method converts a type to a double type.

4. Which of the following operator represents a conditional operation in C#?


A - ?:
B - is
C - as
D-*
Answer : A

Explanation
?: operator represents a conditional operation.

5. Which of the following access specifier in C# allows a class to hide its member variables and
member functions from other functions and objects?
A - Public
B - Private
C - Protected
D - Internal
Answer : B

Explanation

Private access specifier allows a class to hide its member variables and member functions from
other functions and objects.

6. Which of the following is correct about nullable types in C#?


A - C# provides a special data types, the nullable types, to which you can assign normal range of
values as well as null values.
B - You can assign true, false, or null in a Nullable<bool> variable.
C - You can store any value from -2,147,483,648 to 2,147,483,647 or null in a Nullable<Int32>
variable.
D - All of the above.
Answer : D

Explanation

All of the above statements are correct.

7. Which of the following is true about C# enumeration?


A - An enumerated type is declared using the enum keyword.
B - C# enumerations are value data type.
C - Enumeration contains its own values and cannot inherit or cannot pass inheritance.
D - All of the above.
Answer : D

Explanation

All of the above options are correct.

8. Which of the following preprocessor directive allows you to undefine a symbol in C#?
A - define
B - undef
C - region
D - endregion
Answer : B
Explanation

#undef: It allows you to undefine a symbol.

9. What is a correct syntax to output "Hello World" in C#?

(a) Console.WriteLine(“Hello World”);


(b)cout << "Hello World";
(c)System.out.println("Hello World");
(d)print ("Hello World");

Answer : A

10. How do you insert COMMENTS in C# code?

(a) // This is a comment


(b)/* This is a comment
(c)# This is a comment
Answer : A

11. C# is an alias of C++

(a) True

(b) False

Answer : B

12. Which data type is used to create a variable that should store text?

(a) string
(b)Txt
(c)str
(d)myString

Answer : A

13. How do you create a variable with the numeric value 5?

(a) num x=5


(b) x=5;
(c) int x=5;
(d) double x=5;

Answer : C
14. How do you create a variable with the floating number 2.8?

(a) double x=2.8D;


(b)int x = 2.8;
(c)int x = 2.8D;
(d)byte x = 2.8

Answer : A

15. Which property can be used to find the length of a string?


(a) length()

(b) getLength()

(c) Length

(d) length

Answer : C

16. Which operator is used to add together two values?

(a) The & Sign

(b) The * Sign

(c) The + Sign

(d) The - Sign

Answer : C

17. The value of a string variable can be surrounded by single quotes.

(a) False
(b)True
Answer : A

18. Type casting is when you assign a value of one data type to another type.

(a) True
(b)False
Answer : A
19. Which operator can be used to compare two values?

(a) ==
(b)<>
(c)=
(d)><
Answer : A

20. How do you create a method in C#?

(a) MyMethod()
(b)myMethod[]
(c)(MyMethod)
(d)MyMethod.
Answer : A

21. Which keyword is used to create a class in C#?

(a)MyClass
(b)className
(c)class()
(d)class
Answer : D

22. What is the correct way to create an object called myObj of MyClass?

(a)class MyClass = new myObj();


(b)new myObj = MyClass();
(c)class myObj = new MyClass();
(d) MyClass myObj = new MyClass();
Answer : D

23. What is the name of the 'special' class that represents a group of constants?

(a)special
(b)void
(c)const
(d)enum
Answer : D
24. Which operator is used to multiply numbers?

(a) *
(b) %
(c) x
(d) #
Answer : A

25. Which access modifier makes the code only accessible within the same class?

(a)private
(b)final
(c)public
(d)abstract
Answer : A

26. How do you start writing an if statement in C#?

(a) if x > y:
(b) if (x > y)
(c)if x > y then:
Answer : B

27. Which keyword is used to return a value inside a method?

(a)return
(b)void
(c)get
(d)break
Answer : A

28. Which statement is used to stop a loop?

(a)break
(b)return
(c)exit
(d)stop
Answer : A

29. How do you start writing a while loop in C#?


(a) while x > y:
(b) while (x > y)
(c) while x > y {
(d) x > y while {
Answer : AB

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

1. class z
2. {
3. public string name1;
4. public string address;
5. public void show()
6. {
7. Console.WriteLine("{0} is in city{1}", name1, " ", address);
8. }
9. }
10. class Program
11. {
12. static void Main(string[] args)
13. {
14. z n = new z();
15. n.name1 = "harsh";
16. n.address = "new delhi";
17. n.show();
18. Console.ReadLine();
19. }
20. }
a) Syntax error
b) {0} is in city{1} harsh new delhi
c) harsh is in new delhi
d) Run successfully prints nothing

Answer: c
Explanation: Member function show() accessed using object of class ‘z’ which is ‘n’ as
object.member().

31. A type of class which does not have its own objects but acts as a base class for its subclass is
known as?
a) Static class
b) Sealed class
c) Abstract class
d) None of the mentioned
Answer: c
32. Which of the given modifiers can be used to prevent Method overriding?
a) Static
b) Constant
c) Sealed
d) final
Answer: c
Explanation: When an instance method declaration includes the sealed modifier, the method is
said to be sealed method. It means a derived class cannot override this method.

33. To implement delegates, the necessary condition is?


a) class declaration
b) inheritance
c) runtime polymorphism
d) exceptions

Answer: a

34. 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

Answer: c

35. Which among the following is the correct statement about delegate declaration?

delegate void del(int i);

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

Answer: d

36. Which of the following is the object oriented way to handle run time errors?
a) Error codes
b) HERRESULT
c) OnError
d) Exceptions
Answer: d
37. Choose the keyword which declares the indexer?
a) base
b) this
c) super
d) extract
Answer: b
Explanation: The indexer is declared using the name this.

38. 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
Answer: c
Explanation: The indexer is implemented through the get and set accessors for the [] operator as:
public double this[int idx]
{
get
{
if()
{
}
else
{
return([idx]);
}

}
set
{
array[idx];

}
}
39. 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
Answer: c

40. The modifiers used to define an array of parameters or list of arguments is __________
a) ref
b) out
c) param
d) var
Answer: c

41. Types of ‘Data Conversion’ in C#?


a) Implicit Conversion
b) Explicit Conversion
c) Implicit Conversion and Explicit Conversion
d) None of the mentioned
Answer: b

42. Number of constructors a class can define is?


a) 1
b) 2
c) Any number
d) None of the mentioned
Answer: c
Explanation: A constructor is a simple method which has the same name as the class and hence
used to create object of a class. C# class can define any number of constructors. Every class
contains a default constructor.

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

1. class abc
2. {
3. int i;
4. float k;
5. public abc(int ii, float kk)
6. {
7. i = ii;
8. k = kk;
9. }
10. }
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);

Answer: d
Explanation: Return types of parameters of object of class matches with defined constructor
arguments types.

44. Which of the following string() method are used to compare two strings with each other?
a) CopyTo()
b) Copy()
c) Compare()
d) CompareTo()
Answer: d
Explanation: In C#, the CompareTo() method is used to compare two strings and determine
their relationship. It returns 0 if the strings are equal, a negative value if the first string is
less, and a positive value if the first string is greater.

45. Syntax for declaration and initialization of data variable is?


a) <data type><var_name> = <Value>;
b) <data type><var_name>;
c) <var_name><data type>;
d) <var_name> = <value>;
Answer: a

You might also like