C# MCQ
C# MCQ
Explanation
Explanation
Explanation
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.
Explanation
Explanation
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
Answer : A
(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
Answer : C
14. How do you create a variable with the floating number 2.8?
Answer : A
(b) getLength()
(c) Length
(d) length
Answer : C
Answer : C
(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
(a) MyMethod()
(b)myMethod[]
(c)(MyMethod)
(d)MyMethod.
Answer : A
(a)MyClass
(b)className
(c)class()
(d)class
Answer : D
22. What is the correct way to create an object called myObj of MyClass?
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
(a) if x > y:
(b) if (x > y)
(c)if x > y then:
Answer : B
(a)return
(b)void
(c)get
(d)break
Answer : A
(a)break
(b)return
(c)exit
(d)stop
Answer : A
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.
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?
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
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.