linux-packaging-mono/mcs/tests/gtest-variance-1.cs

33 lines
456 B
C#
Raw Permalink Normal View History

interface IFoo<out T>
{
T Bar { get; }
}
class Foo : IFoo<string>
{
readonly string bar;
public Foo (string bar)
{
this.bar = bar;
}
public string Bar { get { return bar; } }
}
public class Test
{
public static int Main ()
{
string bar = "Who is John Galt?";
IFoo<string> foo = new Foo(bar);
IFoo<object> foo2 = foo;
if (!foo2.Bar.Equals (bar))
return 1;
foo2 = new Foo(bar);
if (foo2.Bar != bar)
return 2;
return 0;
}
}