Uses for static generic classes?

前端 未结 9 1744
猫巷女王i
猫巷女王i 2020-12-08 10:11

What are the key uses of a Static Generic Class in C#? When should they be used? What examples best illustrate their usage?

e.g.

         


        
9条回答
  •  庸人自扰
    2020-12-08 10:48

    The first blog post you mention shows a valid use (as a static repository class for an ActiveRecord implementation):

    public static class Repository
    {
        public static T[] FindAll { }
    
        public static T GetById(int id){ }
    
        public static void Save(T item) { }
    }
    

    Or if you wanted to implement different sort methods for Generic arrays:

    public static class ArraySort
    {
        public static T[] BubbleSort(T[] source) { }
    
        public static T[] QuickSort(T[] source) { }
    }
    

提交回复
热议问题