Skip to content

Instantly share code, notes, and snippets.

@johnallers
Created February 9, 2012 01:15
Show Gist options
  • Save johnallers/1776195 to your computer and use it in GitHub Desktop.
Save johnallers/1776195 to your computer and use it in GitHub Desktop.
Quick demo of how optional parameters work with interfaces.
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