Answers for "how to get a subset of a list in c#"

C#
0

how to get a subset of a list in c#

using System;
using System.Linq;



public class MainClass
{
	public static void Main()
	{
		int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
		int offset = 0;
		int length = 3;

		var subArray = array.Skip(offset).Take(length).ToArray();
		Console.WriteLine(String.Join(",", subArray));
	}
}

/*
	Output: 1,2,3, this will return the first elements of the array
*/
Posted by: Guest on October-21-2020

Code answers related to "how to get a subset of a list in c#"

C# Answers by Framework

Browse Popular Code Answers by Language