Get Or Create List<T> - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

Get Or Create List<T>

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from  ww  w. j av  a2  s. c o  m

public class Main{
    public static List<T> GetOrCreate<T>(ref List<T>[] arr, uint index)
      {
         if (index >= arr.Length)
         {
            EnsureSize(ref arr, (int)(index * LoadConstant) + 1);
         }

         var list = arr[index];
         if (list == null)
         {
            return arr[index] = new List<T>();
         }
         return list;
      }
}

Related Tutorials