Technical Knowledge

目次

C#

[言語]

型引数の型のインスタンスを生成。

new() 制約が必要。

class Factory <T> where T : new ()
{
	public T create()
	{
		return new T();
	}
}
var factory = new Factory<ClassA>();
ClassA a = factory.create();

<2011-08-04 木>

Date: 2022-04-24