请教,关于泛型工厂~
请问 ITraffic where T : new() 这段代码是什么意思?using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace 工厂模式
{
interface ITraffic
{
void CreateTool();
}
class Factory<T> : ITraffic where T : new()
{
public Factory()
{
}
public void CreateTool()
{
T tool = new T();
}
}
class Car
{
public Car()
{
Console.WriteLine("汽车Car");
}
}
class Moto
{
public Moto()
{
Console.WriteLine("摩托Moto");
}
}
class TestMain
{
static void Main(string[] args)
{
ITraffic car = new Factory<Car>();
car.CreateTool();
ITraffic moto = new Factory<Moto>();
moto.CreateTool();
Console.Read();
}
}
}