Explore topic-wise MCQs in C Sharp Programming.

This section includes 128 Mcqs, each offering curated multiple-choice questions to sharpen your C Sharp Programming knowledge and support exam preparation. Choose a topic below to get started.

101.

From the following code identify the which traversal of a binary tree is this __________

A. Inorder traversal
B. Euler Tour traversal
C. Post-order traversal
D. Pre-order Traversal
Answer» C. Post-order traversal
102.

What is the time complexity of Kruskal’s algorithm?

A. O(ElogV)
B. O(V+logE)
C. O(E+1)
D. O(V²)
Answer» B. O(V+logE)
103.

A polytree is called _______________

A. directed acyclic graph
B. directed cyclic graph
C. bipartite graph
D. connected graph
Answer» B. directed cyclic graph
104.

A linear graph consists of vertices arranged in a line.

A. false
B. true
C. either true or false
D. cannot determined
Answer» C. either true or false
105.

In an n-ary tree, each vertex has at most ______ children.

A. n
B. n⁴
C. n*n
D. n-1
Answer» B. n⁴
106.

The tree elements are called __________

A. vertices
B. nodes
C. points
D. edges
Answer» C. points
107.

What is a bipartite graph?

A. a graph which contains only one cycle
B. a graph which consists of more than 3 number of vertices
C. a graph which has odd number of vertices and even number of edges
D. a graph which contains no cycles of odd length
Answer» E.
108.

Two labeled trees are isomorphic if ____________

A. graphs of the two trees are isomorphic
B. the two trees have same label
C. graphs of the two trees are isomorphic and the two trees have the same label
D. graphs of the two trees are cyclic
Answer» D. graphs of the two trees are cyclic
109.

A graph which consists of disjoint union of trees is called ______

A. bipartite graph
B. forest
C. caterpillar tree
D. labeled tree
Answer» C. caterpillar tree
110.

An n-vertex graph has ______ edges.

A.
B. n-1
C. n*n
D. n*(n+1)/2
Answer» C. n*n
111.

What is a star tree?

A. A tree having a single internal vertex and n-1 leaves
B. A tree having n vertices arranged in a line
C. A tree which has 0 or more connected subtrees
D. A tree which contains n vertices and n-1 cycles
Answer» B. A tree having n vertices arranged in a line
112.

An undirected graph G which is connected and acyclic is called ____________

A. bipartite graph
B. cyclic graph
C. tree
D. forest
Answer» D. forest
113.

If Sample class has a Length property with set accessor then which of the following statements will work correctly?

A. Sample m = new Sample(); int l; l = m.Length;
B. Sample m = new Sample(); m.Length = m.Length + 20;
C. Sample.Length = 20;
D. Console.WriteLine (Sample.Length);
Answer» E.
114.

If a Student class has an indexed property which is used to store or retrieve values to/from an array of 5 integers, then which of the following are the correct ways to use this indexed property? Student[3] = 34; Student s = new Student(); s[3] = 34; Student s = new Student(); Console.WriteLine(s[3]); Console.WriteLine(Student[3]); Student.this s = new Student.this(); s[3] = 34;

A. 1, 2
B. 2, 3
C. 3, 4
D. 3, 5
Answer» C. 3, 4
115.

An Account class has a property called accountNo and acc is a reference to a bank object and we want the C#.NET code snippet given below to work. Which of the following options will ensure this functionality? acc.accountNo = 10; Console.WriteLine(acc.accountNo);

A. Declare accountNo property with both get and set accessors.
B. Declare accountNo property with only get accessor.
C. Declare accountNo property with get, set and normal accessors.
D. Declare accountNo property with only set accessor.
Answer» B. Declare accountNo property with only get accessor.
116.

Which of the following is the correct way to implement a write only property Length in a Sample class?

A. class Sample { public int Length { set { Length = value; } } }
B. class Sample { int len; public int Length { get { return len; } set { len = value; } } }
C. class Sample { int len; public int Length { WriteOnly set { len = value; } } }
D. class Sample { int len; public int Length { set { len = value; } } }
Answer» E.
117.

Suppose a Student class has an indexed property. This property is used to set or retrieve values to/from an array of 5 integers called scores[]. We want the property to report "Invalid Index" message if the user attempts to exceed the bounds of the array. Which of the following is the correct way to implement this property?

A. class Student { int[] scores = new int[5] {3, 2, 4,1, 5}; public int this[ int index ] { set { if (index < 5) scores[index] = value; else Console.WriteLine("Invalid Index"); } } }
B. class Student { int[] scores = new int[5] {3, 2, 4, 1, 5}; public int this[ int index ] { get { if (index < 5) return scores[ index ]; else { Console.WriteLine("Invalid Index"); return 0; } } set { if (index < 5) scores[ index ] = value; else Console.WriteLine("Invalid Index"); } } }
C. class Student { int[] scores = new int[5] {3, 2, 4, 1, 5}; public int this[ int index ] { get { if (index < 5) return scores[ index ]; else { Console.WriteLine("Invalid Index"); return 0; } } } }
D. class Student { int[] scores = new int[5] {3, 2, 4, 1, 5}; public int this[ int index ] { get { if (index < 5) scores[ index ] = value; else { Console.WriteLine("Invalid Index"); } } set { if (index < 5) return scores[ index ]; else { Console.WriteLine("Invalid Index"); return 0; } } } }
Answer» C. class Student { int[] scores = new int[5] {3, 2, 4, 1, 5}; public int this[ int index ] { get { if (index < 5) return scores[ index ]; else { Console.WriteLine("Invalid Index"); return 0; } } } }
118.

An Employee class has a property called age and emp is reference to a Employee object and we want the statement Console.WriteLine(emp.age) to fail. Which of the following options will ensure this functionality?

A. Declare age property with only get accessor.
B. Declare age property with only set accessor.
C. Declare age property with both get and set accessors.
D. Declare age property with get, set and normal accessors.
Answer» C. Declare age property with both get and set accessors.
119.

A property can be declared inside a namespace or a procedure.

A. 1
B.
Answer» C.
120.

Which of the following is the correct way to implement a read only property Length in a Sample class?

A. class Sample { int len; public int Length { get { return len; } } }
B. class Sample { public int Length { get { return Length; } } }
C. class Sample { int len; public int Length { get { return len; } set { len = value; } } }
D. class Sample { int len; public int Length { Readonly get { return len; } } }
Answer» B. class Sample { public int Length { get { return Length; } } }
121.

If Sample class has a Length property with get and set accessors then which of the following statements will work correctly? Sample.Length = 20; Sample m = new Sample(); m.Length = 10; Console.WriteLine(Sample.Length); Sample m = new Sample(); int len; len = m.Length; Sample m = new Sample(); m.Length = m.Length + 20;

A. 1, 3
B. 2, 4, 5
C. 4 only
D. 3, 5
Answer» C. 4 only
122.

Which of the following statements are correct? The signature of an indexer consists of the number and types of its formal parameters. Indexers are similar to properties except that their accessors take parameters. Accessors of interface indexers use modifiers. The type of an indexer and the type of its parameters must be at least as accessible as the indexer itself. An interface accessor contains a body.

A. 1, 3, 5
B. 1, 2, 4
C. 3, 5
D. 2, 4
Answer» C. 3, 5
123.

Which of the folowing does an indexer allow to index in the same way as an array? A class A property A struct A function An interface

A. 1, 3, 5
B. 2, 4
C. 3, 5
D. 3, 4, 5
Answer» B. 2, 4
124.

Which of the following statements is correct about properties used in C#.NET?

A. A property can simultaneously be read only or write only.
B. A property can be either read only or write only.
C. A write only property will have only get accessor.
D. A write only property will always return a value.
Answer» C. A write only property will have only get accessor.
125.

If Sample class has a Length property with get accessor then which of the following statements will work correctly?

A. Sample m = new Sample(); m.Length = 10;
B. Sample m = new Sample(); m.Length = m.Length + 20;
C. Sample m = new Sample(); int l; l = m.Length;
D. Sample.Length = 20;
Answer» D. Sample.Length = 20;
126.

If a class Student has an indexer, then which of the following is the correct way to declare this indexer to make the C#.NET code snippet given below work successfully? Student s = new Student(); s[1, 2] = 35;

A. class Student { int[ ] a = new int[5, 5]; public property WriteOnly int this[int i, int j] { set { a[i, j] = value; } } }
B. class Student { int[ , ] a = new int[5, 5]; public int property WriteOnly { set { a[i, j] = value; } } }
C. class Student { int[ , ] a = new int[5, 5]; public int this[int i, int j] { set { a[i, j] = value; } } }
D. class Student { int[ , ] a = new int[5, 5]; int i, j; public int this { set { a[i, j] = value; } } }
Answer» D. class Student { int[ , ] a = new int[5, 5]; int i, j; public int this { set { a[i, j] = value; } } }
127.

A Student class has a property called rollNo and stu is a reference to a Student object and we want the statement stu.RollNo = 28 to fail. Which of the following options will ensure this functionality?

A. Declare rollNo property with both get and set accessors.
B. Declare rollNo property with only set accessor.
C. Declare rollNo property with get, set and normal accessors.
D. Declare rollNo property with only get accessor.
Answer» E.
128.

A property can be declared inside a class, struct, Interface.

A. 1
B.
C. A property can simultaneously be read only or write only.
D. A property can be either read only or write only.
Answer» B.