RosettaCodeData/Task/Constrained-genericity/C-sharp/constrained-genericity-4.cs

16 lines
288 B
C#

using System.Collections.Generic
class FoodMakingBox<T> where T : IEatable, new()
{
List<T> food;
void Make(int numberOfFood)
{
this.food = new List<T>();
for (int i = 0; i < numberOfFood; i++)
{
this.food.Add(new T());
}
}
}