C# List GetRange() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
List

Definition

In C#, List.GetRange(index, count) cuts out a block of items and gives you a new list that holds them. You say where the block starts and how many items it has.

The original list is not changed. The copy is shallow: for numbers and strings you get independent values, but for classes the new list holds the same objects as the old one. If you want to cut the block out of the list instead, use RemoveRange().

This is an instance member of List<T> (System.Collections.Generic). Call it on a list variable, such as numbers.GetRange(...). A List<T> is a class, so two variables can share one list. It keeps items in the order you put them, allows duplicates, and grows when needed. An array, by comparison, has a fixed length.

Syntax

Pass the start index and the number of items to copy (not the end index).

C#
List<int> numbers = new List<int> { 10, 20, 30, 40, 50 };
List<int> middle = numbers.GetRange(1, 3);   // 20, 30, 40
CallWhat it does
numbers.GetRange(1, 3)A new list with the items at indexes 1, 2, and 3.
numbers.GetRange(0, 2)The first two items.
numbers.GetRange(numbers.Count, 0)Allowed. Returns an empty list.

If index or count is negative, the call throws ArgumentOutOfRangeException. If index + count is more than Count, it throws ArgumentException. The cost is O(count). Newer code can use Slice() or the range operator for the same job.

Library declarations
C#
public List<T> GetRange(int index, int count);

Parameters

ParameterDescription
indexRequired. The zero-based index where the block starts.
countRequired. How many items to copy. index + count must not be more than Count.

Return Value

Return ValueDescription
ListA new list with a shallow copy of the block. The source list is unchanged.

C# Examples

Example 1 — Copy the Middle of a List

Take three items from the middle. The original list is untouched.

C#
using System;
using System.Collections.Generic;

class Program {
    static void Main() {
        List<int> numbers = new List<int> { 10, 20, 30, 40, 50 };

        List<int> middle = numbers.GetRange(1, 3);

        Console.WriteLine(string.Join(", ", middle));
        Console.WriteLine(string.Join(", ", numbers));
        Console.WriteLine(middle.Count);
    }
}

How It Works

  1. Start and size. 1 is the first index to copy and 3 is the number of items, so indexes 1, 2, and 3 are copied.
  2. New list. middle is a separate list holding 20, 30, 40 in their original order.
  3. Source intact. The second line shows numbers still has all five items.
  4. Own count. middle.Count is 3. Changing the copy later has no effect on the five-item original.

Example 2 — Shallow Copy with Objects

Copy a block of objects. The copy is a new list, but the objects inside are shared.

C#
using System;
using System.Collections.Generic;

class Box {
    public int Value;
}

class Program {
    static void Main() {
        List<Box> boxes = new List<Box> {
            new Box { Value = 1 }, new Box { Value = 2 }, new Box { Value = 3 }
        };

        List<Box> part = boxes.GetRange(0, 2);

        part[0].Value = 99;
        part.Add(new Box { Value = 7 });

        Console.WriteLine(boxes[0].Value);
        Console.WriteLine(boxes.Count);
        Console.WriteLine(part.Count);
    }
}

How It Works

  1. Two lists, shared boxes. part holds the first two Box references of boxes. The objects themselves are not duplicated.
  2. Edit through the copy. part[0].Value = 99 changes the object that both lists point to, so boxes[0].Value prints 99.
  3. List shape is separate. Adding a box to part only grows part. boxes still has 3 items.
  4. Need a deep copy? Build new objects yourself, for example with ConvertAll(b => new Box { Value = b.Value }).

Example 3 — Split a List into Pages

Walk through a list in blocks of three, using Math.Min so the last short page does not run past the end.

C#
using System;
using System.Collections.Generic;

class Program {
    static void Main() {
        List<int> items = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8 };
        int pageSize = 3;

        for (int start = 0; start < items.Count; start += pageSize) {
            int length = Math.Min(pageSize, items.Count - start);
            List<int> page = items.GetRange(start, length);
            Console.WriteLine(string.Join(", ", page));
        }
    }
}

How It Works

  1. Jump by page size. start goes 0, 3, 6, so each loop turn begins a new page.
  2. Protect the end. At start = 6 only 2 items remain. Math.Min(3, 2) picks 2, so the range stays inside the list.
  3. Without Min. Asking for 3 items at index 6 would run past the end and throw ArgumentException.
  4. Three copies. Each page is its own small list. The original items list still holds all eight numbers.

Frequently Asked Questions

It copies a block of count items that starts at index into a new List<T>. The original list is not changed.
No, it is shallow. For classes, both lists hold the same objects. For numbers and strings you effectively get independent values.
GetRange copies a block into a new list. RemoveRange deletes the block from the list itself.
GetRange throws ArgumentException when index + count is more than Count, and ArgumentOutOfRangeException for negative values.
They do the same job. Slice(start, length) exists so that the C# range syntax, such as list[1..4], works on a List<T>.

Next: IndexOf()

Return the index of the first item that equals a value, or -1 if it is not found.

IndexOf() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful