public void Run() { //call service, etc. var result = new Result { Success = true, Data = 5 }; Console.WriteLine(result.Success); Console.WriteLine(result.Data); var result2 = new Result2 { Success = false, Data = "Hello" }; Console.WriteLine(result2.Success); Console.WriteLine(result2.Data); }
public void Run() { // VS knows this isa generic so Intellisense is going to kick up T to remind us to pass type var result = new Result2 <int> { Success = true, Data = 5 }; var result2 = new Result2 <string> { Success = true, Data = "Hello" }; var result3 = new Result2 <float> { Success = true, Data = 5.4f }; var helper = new Result2Printer(); helper.Print(result); helper.Print(result2); helper.Print(result3); }
//we want to pass in an instance of a result and print it out public void Print <T>(Result2 <T> result) { Console.WriteLine(result.Success); Console.Write(result.Data); }