下面是我正在做的一个简单示例。基本上,我有多个接口,可以通过1个类或单独的类实现,因此我将每个接口存储在应用程序中。我唯一的问题是关于变量myInterface,yourInterface和ourInterface。 他们引用同一个对象还是有3个不同的对象?在.Net中实现多个接口和对象实例
interface IMyInterface
{
void MyFunction();
}
interface IYourInterface()
{
void YourFunction();
}
interface IOurInterface()
{
void OurFunction();
}
public class MainImplementation : IMyInterface, IYourInterface, IOurInterface
{
public void MyFunction() { }
public void YourFunction() { }
public void OurFunction() { }
}
private IMyInterface myInterface;
private IYourInterface yourInterface;
private IOurInterface ourInterface;
static void Main(string[] args)
{
myInterface = new MainImplementation() as IMyInterface;
yourInterface = myInterface as IYourInterface;
ourInterface = myInterface as IOurInterface;
}
奖励:有没有更好的方法来做到这一点?
我对这个问题的标题有点困惑。 ByVal或ByRef与提供的代码示例有什么关系?没有任何方法采用任何参数。 – JohnFx 2009-08-19 01:15:43
修正了它。希望,这有点更好。这是一个漫长的一天:) – kevindaub 2009-08-19 01:17:28