Govt. Exams
Entrance Exams
Properties with accessors (get/set) follow encapsulation principles, allowing controlled access while maintaining data validation logic within the property.
The 'virtual' keyword marks a method in the base class as overridable. Derived classes can use 'override' to provide their own implementation.
'where' clause in generic types constrains type parameters (e.g., where T : class, where T : IComparable). C# 11 added 'allows ref struct' constraint.
Composition (HAS-A) and Inheritance (IS-A) serve different purposes. Composition is more flexible and often preferred over inheritance to avoid tight coupling.
Explicit interface implementation is always private by convention and accessed through interface reference only, not through class instance directly.
Records (C# 9+) are designed for immutable data with positional parameters, automatic value-based equality, and ToString() implementation.
If you override a non-virtual method, C# will hide it and show a compiler warning. Use 'new' keyword to suppress the warning and explicitly hide the base method.
Overloading creates multiple methods with the same name but different parameters. Overriding replaces a base class method in a derived class.
The 'init' accessor (introduced in C# 9) allows setting the property only during initialization. Any modification attempt post-initialization causes a compile-time error.
C# 11 introduced the 'required' keyword that enforces callers to initialize specific members during object instantiation.