Optional parameters for interfaces
        Posted  
        
            by bryanjonker
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by bryanjonker
        
        
        
        Published on 2010-04-02T14:33:48Z
        Indexed on 
            2010/04/02
            14:43 UTC
        
        
        Read the original article
        Hit count: 279
        
Using c# 4.0 -- building an interface and a class that implements the interface. I want to declare an optional parameter in the interface and have it be reflected in the class. So, I have the following:
 public interface IFoo
 {
      void Bar(int i, int j=0);
 }
 public class Foo
 {
      void Bar(int i, int j=0) { // do stuff }
 }
This compiles, but it doesn't look right. The interface needs to have the optional parameters, because otherwise it doesn't reflect correctly in the interface method signature.
Should I skip the optional parameter and just use a nullable type? Or will this work as intended with no side effects or consequences?
© Stack Overflow or respective owner