Comments on: Array Slicing in C# https://code-maze.com/csharp-array-slicing/ Learn. Code. Succeed. Wed, 13 Jul 2022 10:04:44 +0000 hourly 1 https://wordpress.org/?v=6.7.5 By: Vladimir Pecanac https://code-maze.com/csharp-array-slicing/#comment-5256 Sat, 12 Mar 2022 11:25:28 +0000 https://drafts.code-maze.com/?p=66876#comment-5256 In reply to Magomed Mirzaev.

That’s right Magomed.
For those wondering, we can do this now:

var listOfNumbers = new List<int>()
{
	1, 2, 3, 4, 5, 6, 7
};

var bla = listOfNumbers.Skip(2).Take(2..4);

The result would be 5, 6.

]]>
By: Magomed Mirzaev https://code-maze.com/csharp-array-slicing/#comment-5255 Sat, 12 Mar 2022 10:27:44 +0000 https://drafts.code-maze.com/?p=66876#comment-5255 Since C# 10 we can pass range to the Take method of LINQ

]]>
By: Marinko Spasojević https://code-maze.com/csharp-array-slicing/#comment-5250 Fri, 11 Mar 2022 16:56:25 +0000 https://drafts.code-maze.com/?p=66876#comment-5250 In reply to Joel.

Thank you Joel a lot. Those are great suggestions and we have updated the article, you just need to refresh the page if you can’t see the updates (due to caching). Just regarding the part you are not agreeing with – I agree with you, we just didn’t mention Span here so we didn’t choose it over ReadOnlySpan. But, we fixed that. It should be mentioned.

]]>
By: Joel https://code-maze.com/csharp-array-slicing/#comment-5241 Thu, 10 Mar 2022 15:42:28 +0000 https://drafts.code-maze.com/?p=66876#comment-5241 It’s probably worth mentioning that the Range Operator approach allocates new arrays when you use it on an array, and does not when you use it on a Span.

However, we might have some other algorithms that update our data regularly, in this case, we should use ArraySegment.”

I disagree with this. If you need to update data, use Span<T> instead of ReadOnlySpan<T>. There’s few if any scenarios where ArraySegment is better than Span.

]]>