K
kasper.rung
I am having trouble implementing an interface. The interface requires
a method to return an object, but it does not seem to be able to treat
a reference type as an object. I have the following sample code:
using System;
using System.Collections.Generic;
using System.Text;
namespace GenericsTest
{
public interface IMyClass
{
object Foo();
}
public class MyClass<T> : IMyClass where T : class
{
public T Foo()
{
// Foo
}
}
}
Howcome the public T Foo() is not returning an object even when T is
constrained to be only of reference type? Doesn't that automatically
ensure we are dealing with objects?
Thank you, Kasper
a method to return an object, but it does not seem to be able to treat
a reference type as an object. I have the following sample code:
using System;
using System.Collections.Generic;
using System.Text;
namespace GenericsTest
{
public interface IMyClass
{
object Foo();
}
public class MyClass<T> : IMyClass where T : class
{
public T Foo()
{
// Foo
}
}
}
Howcome the public T Foo() is not returning an object even when T is
constrained to be only of reference type? Doesn't that automatically
ensure we are dealing with objects?
Thank you, Kasper