关于c#工厂模式
using System;using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
public class one
{
public virtual void print()
{ }
}
public class two : one
{
public override void print()
{
Console.Write("two方法");
}
}
public class three : one
{
public override void print()
{
Console.Write("three方法");
}
}
public class im
{
public static one returnclass(string name)
{
switch (name)
{
case "two":
return new two();
case "three":
return new three();
}
// return null;
}
}
class Program
{
static void Main(string[] args)
{
one adm = im.returnclass("three");
adm.print();
}
}
}
请问一下。。c#中的工厂模式是不是一定要使用抽象类来定义呢?还有。在returnclass函数中。为何将return null注释后,提示错误呢?为何不能注释掉呢?