12345678910111213141516171819202122232425262728293031323334353637 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleGeneric
- {
-
- public interface IGenericInterface<T>
- {
- T CreateInstance();
-
-
-
- public class Factory<T, TI> : IGenericInterface<TI> where T : TI, new()
- {
- public TI CreateInstance()
- {
- return new T();
- }
- }
- }
- internal class Program
- {
- static void Main(string[] args)
- {
- IGenericInterface<System.ComponentModel.IListSource> factory = new Factory<System.Data.DataTable, System.ComponentModel.IListSource>();
-
- Console.WriteLine(factory.CreateInstance().GetType().ToString());
- Console.ReadLine();
- }
- }
- }
|