Click here to Skip to main content
15,305,508 members
Articles / Programming Languages / C#
Posted 26 Oct 2010

Tagged as


1 bookmarked

Interface & Property

Rate me:
Please Sign up or sign in to vote.
2.25/5 (8 votes)
27 Oct 2010CPOL
Shows How can you keep property field as part of interface & how it will be implemented
This Tip shows how do you keep property as part of the interface, how do you implement that property on your class.

Consider the inteface below:
interface IBus
    float DiscountPrice {get;}

Here, we specified that implementor of this interface, should implement the property DiscountPrice. Also, note that we asked for retrieval of the property value only needs to be implemented.

Below is the class that implements the above interface property:
public class SchoolBus:IBus
    private int Price = 8000;
    //Implementing the property
    public float DiscountPrice
        get { return price * 0.95f; }


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sivaraman Dhamodharan
Software Developer iSOFT
India India
I am working as software engineer in iSOFT R&D. I have been come across C++,MFC, .net technologies. I do like playing video games, reading books.


Comments and Discussions

GeneralThanks Toli. Pin
Sivaraman Dhamodharan9-Nov-10 21:17
MemberSivaraman Dhamodharan9-Nov-10 21:17 
General"johannesnestler" - Thanks for your very open comment. This ... Pin
Sivaraman Dhamodharan30-Oct-10 20:32
MemberSivaraman Dhamodharan30-Oct-10 20:32 
GeneralReason for my vote of 1 come on - next time you post a tip h... Pin
johannesnestler28-Oct-10 23:59
Memberjohannesnestler28-Oct-10 23:59 
GeneralReason for my vote of 3 Moderate Pin
Toli Cuturicu28-Oct-10 6:06
MemberToli Cuturicu28-Oct-10 6:06 
Reason for my vote of 3
GeneralReason for my vote of 1 Although it is possible to write on ... Pin
BillW3328-Oct-10 5:13
professionalBillW3328-Oct-10 5:13 
GeneralReason for my vote of 1 No value at all Pin
Kevin Marois27-Oct-10 8:06
professionalKevin Marois27-Oct-10 8:06 
GeneralAt least I can away from FroggieFrog's point 2. Corrected th... Pin
Sivaraman Dhamodharan27-Oct-10 7:38
MemberSivaraman Dhamodharan27-Oct-10 7:38 
GeneralReason for my vote of 1 1. VERY trivial. 2. Code cannot comp... Pin
FroggieFrog27-Oct-10 0:16
MemberFroggieFrog27-Oct-10 0:16 
GeneralReason for my vote of 1 it's so simple Pin
RenateN26-Oct-10 7:06
MemberRenateN26-Oct-10 7:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.