Generate a list with n size of T value. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

Generate a list with n size of T value.

Demo Code


using System.Linq;
using System;//  ww  w .  j a  v  a 2s.com
using System.Collections.Generic;
using System.Collections;
using UnityEngine;

public class Main{
        /// <summary>
        /// Generate a list with n size of T value. 
        /// </summary>
        public static List<T> GenerateListWithValues<T>(T value, int count)
        {
            count = Mathf.Max(0, count);

            var toReturn = new List<T>(count);

            for (int i = 0; i < count; i++)
            {
                toReturn.Add(value);
            }

            return toReturn;
        }
}

Related Tutorials