I want to know that i have an interface named as person what is the correct way to implement it?
C#
interface person { String Name { get; set; } }interface person { String Name { get; set; } }Know the answer? Post it. Somebody with the same question will find it here.
VulpesRank #55 · 29.2K reputationPosted Dec 17, 2011, 3:24 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Dec 17, 2011, 1:38 PM EST
It is unfortunate that properties cannot be implemented as Auto-Implemented Properties in derived classes.
VulpesRank #55 · 29.2K reputationPosted Dec 17, 2011, 1:54 PM EST
Posted Dec 19, 2011, 8:47 AM EST
VulpesRank #55 · 29.2K reputationPosted Dec 19, 2011, 8:53 AM EST
You can then write generic code which applies to all types which implement the interface because you know that they must contain certain members even though they'll (usually) be implemented differently.
The purpose of the above example was to show how to implement an interface, not to demonstrate why it's useful.
Sam HobbsRank #107 · 20.5K reputationPosted Dec 19, 2011, 10:51 AM EST
Posted Dec 19, 2011, 11:25 AM EST
VulpesRank #55 · 29.2K reputationPosted Dec 19, 2011, 11:31 AM EST
Posted Dec 19, 2011, 11:51 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Dec 19, 2011, 2:23 PM EST
Posted Dec 20, 2011, 7:31 AM EST
An interface is a collection of methods (and perhaps other members) that can be used by any class, as long as the class provides a definition to override the interface's do-nothing, or abstract, definition.
VulpesRank #55 · 29.2K reputationPosted Dec 20, 2011, 7:59 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Dec 20, 2011, 8:35 AM EST
Can you tell us what book?
Posted Dec 20, 2011, 11:02 AM EST
VulpesRank #55 · 29.2K reputationPosted Dec 21, 2011, 1:47 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Dec 21, 2011, 9:15 AM EST
I assume that most people that buy the book buys it as a class textbook. There are not many programming books that have a list price over $100 except for specialized books containing material that is not available anywhere else.
Sam HobbsRank #107 · 20.5K reputationPosted Dec 21, 2011, 10:19 AM EST
For example, for each standard computer language such as C++ and C# there is just one standard but many compilers implementing that standard. Compilers can add features to a language but if the compiler does not comply with the features described in the standard then the compiler is non-standard.
An interface specifies what a class that implements the interface must do but it does not specify how it is done. An interface could define a stream but a stream could be a disk file stream, a memory stream or a network stream. The interface would for example just specify that a class must provide methods to open and close a stream and to read/write. Some streams would use a buffer but an in-memory (string) stream would not.
Posted Dec 21, 2011, 11:34 AM EST
Sam HobbsRank #107 · 20.5K reputationPosted Dec 21, 2011, 12:01 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts