Created
February 9, 2012 01:15
-
-
Save johnallers/1776195 to your computer and use it in GitHub Desktop.
Quick demo of how optional parameters work with interfaces.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace OptionalParametersOnInterface | |
{ | |
using System; | |
public interface IFoo | |
{ | |
void DoStuff(bool someBit = true); | |
} | |
public class Foo : IFoo | |
{ | |
public void DoStuff(bool someBit = false) | |
{ | |
Console.WriteLine(someBit); | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Foo foo = new Foo(); | |
foo.DoStuff(); | |
// Outputs False | |
IFoo ifoo = foo; | |
ifoo.DoStuff(); | |
// Outputs True | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment