Search code examples
c#interfacemultiple-inheritance

Define constants needed in more than one class


In my smart client solution, I have a Project folder with:

IProjectView.cs 
*ProjectView*  
     ProjectView.cs  
        ProjectView.Designer.cs  
     ProjectView.GeneratedCode.cs  
     ProjectView.resx  
     ProjectViewPresenter.cs  

I want to define some constants for user by ProjectView.cs and ProjectViewPresenter.cs. Both of these classes implement IProjectView.cs, so were I back in Java, I'd put them there. If this were C++, I'd create a class ProjectConstants.cs and have the classes inherit it, but C# doesn't allow multiple inheritance.

How do I do this?


Solution

  • Can having a Read-Only Property in your interface solve your problem?

    string MyReadOnlyProperty { get; }
    

    I have no clue if this is very performance-wise compared to constant thought.