using System.Collections.Generic; public class MyList{ private List list = new List (); public void Add(T item) { list.Add(item); } public T Get(int index) { return list[index]; } }
public class Swap { public static void DoSwapThis template defines a generic method that swaps two variables of any type by reference. It uses a generic type parameter T to replace the actual type of variables. Then, it implements a static method, DoSwap, that takes two parameters by reference and exchanges their values. This template does not require any package library. In summary, C# Template is a powerful feature in C# programming language that allows developers to write reusable and flexible code. It also provides a way to leverage the power of package libraries to extend the functionality of the template.(ref T var1, ref T var2) { T temp = var1; var1 = var2; var2 = temp; } }