split list in sublists c# linq code example

Example 1: split list into sublists with linq

public static IList<IList<T>> Split<T>(IList<T> source)
{
    return  source
        .Select((x, i) => new { Index = i, Value = x })
        .GroupBy(x => x.Index / 3)
        .Select(x => x.Select(v => v.Value).ToList())
        .ToList();
}

Example 2: split list c# linq

void PoolObject()
        {
            foreach (Pool pool in pools)
            {
                characterScore.score *= Numb;

                score = characterScore.score;
                Instantiate(effect, Effect.transform.position, Effect.transform.rotation);

                for (int j = 0; j < score; j++)
                {
                    GameObject obj = Instantiate(pool.poolObject, Position.transform.position, Position.transform.rotation);
                    obj.SetActive(true);
                    

                }
            }