Properties Questions
Practice Properties MCQs with answers and explanations. Page 1 of 1.
Category
C# Programming
Topic
Properties
Page
1 / 1
Mode
Practice
Questions
Open any question to view the answer and explanation.
C#.NET — Implement a read-only property Length correctly in a class.
Open
View answer
C#.NET properties — Which option correctly implements a write-only property named Length in the Sample class?
Open
View answer
C#.NET indexers — A Student class exposes an indexed property over an int[5]. Which usages are correct?
Open
View answer
C#.NET properties — Sample has a Length property with only a set accessor (write-only). Which statements compile and run?
Open
View answer
C#.NET indexers — Student must support two-dimensional indexing as in:
Student s = new Student();
s[1, 2] = 35;
Which declaration enables this write-only indexer?
Open
View answer
C#.NET properties — To allow both assigning and printing acc.accountNo, how should Account.accountNo be declared?
Open
View answer
C#.NET indexers — What kinds of types can declare an indexer and thus be indexed like an array?
Open
View answer
C#.NET properties — We want the statement stu.RollNo = 28 to fail for a Student object. How should the rollNo property be declared?
Open
View answer
C#.NET indexers — Which statements are correct about indexer definitions and interface indexers?
Open
View answer
C#.NET properties — Which statement correctly describes properties?
Open
View answer
C#.NET properties — Sample has a Length property with only a get accessor (read-only). Which statements are valid?
Open
View answer
C#.NET — Properties and accessibility: make Console.WriteLine(emp.age) fail by design.
Scenario:
An Employee class exposes a property named age. There is a reference emp to an Employee object. You want the statement below to fail at compile time (i.e., disallow reading age):
Console.WriteLine(emp.age)
Which option enforces this?
Choose the best design choice.
Open
View answer
C#.NET — Using an instance property with get and set: which statements compile and run?
Assume class Sample defines a non-static property Length with both get and set accessors. Which of the following statements are valid?
Open
View answer
C#.NET — True or False: A property can be declared inside a class, a struct, or an interface.
Open
View answer
C#.NET — Which statement about properties is correct?
Open
View answer
C#.NET — True or False: A property can be declared inside a namespace or inside a procedure (method).
Open
View answer
C#.NET — Implementing a bounds-checked indexed property (indexer) for a 5-element scores array.
Goal: The indexer should print "Invalid Index" when the user accesses beyond the last valid index.
Open
View answer
Practice smarter
Solve a few questions daily and revisit weak topics regularly to improve accuracy.