Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Foo myFoo = new Foo();
- return myFoo is IBar;
- IBar bar = myArrayList[3] as IBar;
- Foo foo = bar as Foo;
- void DoSomething(IBar bar) {
- }
- static void Main() {
- Foo myFoo = new Foo();
- DoSomething(myFoo);
- }
- interface IBar { void happy(); }
- class Foo : IBar
- {
- void happy()
- {
- Console.Write("OH MAN I AM SO HAPPY!");
- }
- }
- class Program
- {
- static void Main()
- {
- IBar myBar = new Foo();
- myBar.happy();
- }
- }
- // Your class implements an interface
- class Concrete : ISomeInterface {}
- // New up an instance of that class
- var myClass = new Concrete();
- // You have a method somewhere that takes ISomeInterface as a parameter
- public void MyMethod(ISomeInterface blah){}
- // You can pass your instance to that method
- MyMethod(myClass);
Add Comment
Please, Sign In to add comment