Skip to content

Instantly share code, notes, and snippets.

@Aurumaker72
Last active March 13, 2023 16:21
Show Gist options
  • Select an option

  • Save Aurumaker72/b57562f81243207e76c5c8f95c7e6716 to your computer and use it in GitHub Desktop.

Select an option

Save Aurumaker72/b57562f81243207e76c5c8f95c7e6716 to your computer and use it in GitHub Desktop.
Multi-dimensional array slicing
public static class ArrayExtensions
{
public static T[] GetColumn<T>(this T[,] matrix, int columnNumber)
{
return Enumerable.Range(0, matrix.GetLength(0))
.Select(x => matrix[x, columnNumber])
.ToArray();
}
public static T[] GetRow<T>(this T[,] matrix, int rowNumber)
{
return Enumerable.Range(0, matrix.GetLength(1))
.Select(x => matrix[rowNumber, x])
.ToArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment