C#.NET — Does the this reference exist for instance (non-static) method calls?
-
ATrue
-
BFalse
Answer
Correct Answer: True
Explanation
Introduction / Context:The keyword this refers to the current instance in an instance (non-static) method. Understanding when this exists is crucial to reasoning about members and overload resolution.
Given Data / Assumptions:
- “Non-shared” means non-static (instance) in C# terminology.
- Static (shared) methods do not have an instance and thus no this.
Concept / Approach:When an instance method is invoked, the runtime passes a hidden reference to the target object as this, enabling access to instance fields, properties, and other methods.
Step-by-Step Solution:
Call an instance method: obj.Member(). A hidden argument is the reference to obj, available inside as this.In static methods, no this is available because there is no specific instance bound.Verification / Alternative check:Inside a static method, referencing this produces a compile-time error; inside an instance method, this compiles and works.
Why Other Options Are Wrong:False would contradict the C# object model for instance methods.
Common Pitfalls:Confusing static context (no this) with instance context (has this).
Final Answer:True