Is interface is value type or Reference type?
Any one Know give me small example.
Thanks inadvance
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
TulasiRank #2,544 · 549 reputationPosted Oct 26, 2011, 9:47 PM EDT
Interface is both(value type and reference type) .
lets see one example
public interface ITest
}
Please mark the answer as Accepted if it helps you.
VulpesRank #55 · 29.2K reputationPosted Oct 27, 2011, 12:32 AM EDT
Although it may appear to act like a value type when you assign a struct to a variable of the interface type, in fact the struct is boxed on the heap and a reference to it is then assigned to the interface variable.
See this previous thread where exactly the same question was asked:
http://www.c-sharpcorner.com/Forums/Thread/144641/c-sharp-interface.aspx
Javeed M ShaikhRank #839 · 2.7K reputationPosted Oct 27, 2011, 5:17 AM EDT
VulpesRank #55 · 29.2K reputationPosted Oct 27, 2011, 7:28 AM EDT
Of course, if you call the GetType() method - which all types inherit from System.Object - this gives you the runtime type of the object (i.e. what it really is) rather than its compile time type.