Click here to Skip to main content
15,867,453 members
Articles / Programming Languages / C#
Tip/Trick

Interface & Property

Rate me:
Please Sign up or sign in to vote.
2.25/5 (8 votes)
27 Oct 2010CPOL 14.4K   1   9
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; }
    }
}

License

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


Written By
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.

Web: www.mstecharticles.com


Comments and Discussions

 
GeneralThanks Toli. Pin
Sivaraman Dhamodharan9-Nov-10 21:17
Sivaraman Dhamodharan9-Nov-10 21:17 
General"johannesnestler" - Thanks for your very open comment. This ... Pin
Sivaraman Dhamodharan30-Oct-10 20:32
Sivaraman 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
johannesnestler28-Oct-10 23:59 
Reason for my vote of 1
come on - next time you post a tip how to initalize an integer or what? I always respect if someone is trying to help the beginners but here is not the right "forum" for this kind of "example".
GeneralReason for my vote of 3 Moderate Pin
Toli Cuturicu28-Oct-10 6:06
Toli Cuturicu28-Oct-10 6:06 
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
Sivaraman Dhamodharan27-Oct-10 7:38 
GeneralReason for my vote of 1 1. VERY trivial. 2. Code cannot comp... Pin
FroggieFrog27-Oct-10 0:16
FroggieFrog27-Oct-10 0:16 
GeneralReason for my vote of 1 it's so simple Pin
RenateN26-Oct-10 7:06
RenateN26-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.