Created
August 9, 2016 07:35
-
-
Save gulbanana/1459ba5233debe6b349ec4d94022007c to your computer and use it in GitHub Desktop.
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
using System; | |
interface IFoo | |
{ | |
void Do(); | |
} | |
class A : IFoo | |
{ | |
public void Do() {} | |
} | |
class B : IFoo | |
{ | |
public void Do() {} | |
} | |
class Goodarray | |
{ | |
static void Main(string[] args) | |
{ | |
var x = new IFoo[2]; | |
x[0] = new A(); | |
x[1] = new B(); | |
Ohyes(x); | |
var y = new IFoo[1]; | |
y[0] = new B(); | |
Ohyes(y); | |
} | |
static void Ohyes(IFoo[] thisArrayContainsFoos) | |
{ | |
thisArrayContainsFoos[0].Do(); | |
Console.WriteLine(thisArrayContainsFoos[0]); | |
thisArrayContainsFoos[0] = new A(); //nothing wrong here! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment