Julian Gonzalez

Generation

generate functionThu, 30 Mar 2023

create interface with method that return generic object and where clausule

public interface IGeneric<T> { T Get(); } public class GenericClass<T> : IGeneric<T> { public T Get() { throw new NotImplementedException(); } } public static class Run { public static void Main() { var igen = new GenericClass<int>(); var sgen = new GenericClass<string>(); DoSomething(igen); DoSomething(sgen); } private static void DoSomething<T>(IGeneric<T> arg) where T : class { Console.WriteLine(arg.Get()); } }

Questions about programming?Chat with your personal AI assistant