G
gleb.alexeev
Hello everyone!
It's my first post here.
Could anyone please explain me the behaviour of the following code?
<code>
interface IFoo<T, P>
{
void Bar(T t, P p); // (1)
void Bar(P p1, P p2); // (2)
}
class NastyFooImpl : IFoo<int, int>
{
void IFoo<int, int>.Bar(int t, int p)
{
Console.WriteLine("void IFoo<int, int>.Bar(int t, int
p)");
}
public void Bar(int p1, int p2)
{
Console.WriteLine("public void Bar(int p1, int p2)");
}
}
class Program
{
static void Test<Foo, T, P> () where Foo : IFoo<T, P>, new()
{
Foo foo = new Foo();
T t = default(T);
P p = default(P);
foo.Bar(t ,p);
foo.Bar(p, p);
}
static void Main(string[] args)
{
Test<NastyFooImpl, int, int>();
}
}
</code>
The output I'm getting using Visual Studio 2005:
<code>
void IFoo<int, int>.Bar(int t, int p)
public void Bar(int p1, int p2)
</code>
When I swap lines (1) and (2), the order of lines of output changes as
well.
Any links are greatly appreciated, especially links to C#
specification.
It's my first post here.
Could anyone please explain me the behaviour of the following code?
<code>
interface IFoo<T, P>
{
void Bar(T t, P p); // (1)
void Bar(P p1, P p2); // (2)
}
class NastyFooImpl : IFoo<int, int>
{
void IFoo<int, int>.Bar(int t, int p)
{
Console.WriteLine("void IFoo<int, int>.Bar(int t, int
p)");
}
public void Bar(int p1, int p2)
{
Console.WriteLine("public void Bar(int p1, int p2)");
}
}
class Program
{
static void Test<Foo, T, P> () where Foo : IFoo<T, P>, new()
{
Foo foo = new Foo();
T t = default(T);
P p = default(P);
foo.Bar(t ,p);
foo.Bar(p, p);
}
static void Main(string[] args)
{
Test<NastyFooImpl, int, int>();
}
}
</code>
The output I'm getting using Visual Studio 2005:
<code>
void IFoo<int, int>.Bar(int t, int p)
public void Bar(int p1, int p2)
</code>
When I swap lines (1) and (2), the order of lines of output changes as
well.
Any links are greatly appreciated, especially links to C#
specification.