Skip to content

Instantly share code, notes, and snippets.

@gulbanana
Created August 9, 2016 07:35
Show Gist options
  • Save gulbanana/1459ba5233debe6b349ec4d94022007c to your computer and use it in GitHub Desktop.
Save gulbanana/1459ba5233debe6b349ec4d94022007c to your computer and use it in GitHub Desktop.
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