int[] tmp = new int[cnt];\nfor (int i = 0; i < cnt; i++)\n{\n tmp[i] = nums[startIdx + i];\n}<\/code><\/pre><\/div>\n\n\n\nThe most traditional approach involves first defining the size of the array and then using a loop to individually set the index values.<\/p>\n\n\n\n
<\/div>\n\n\n\n
<\/span>Solution 2 – LINQ – SKIP\u3001 Take<\/strong><\/span><\/h3>\n\n\n\nint[] tmp = nums.Skip(startIdx).Take(cnt).ToArray();<\/code><\/pre><\/div>\n\n\n\nThis should be one of the most familiar syntaxes for everyone developing in C#, enabling easy accomplishment in just one line.<\/p>\n\n\n\n
<\/div>\n\n\n\n
<\/span>Solution 3 – Range operator<\/strong><\/span><\/h3>\n\n\n\nint[] tmp = nums[startIdx..(startIdx+cnt)];<\/code><\/pre><\/div>\n\n\n\nIn addition to LINQ, the introduction of the Range operator<\/strong> in C# 8.0 has made the process even more straightforward.<\/p>\n\n\n\nThe Range operator can even be combined with the ^ (end operator) <\/strong>for additional operations. For example: nums[startIdx..^3]<\/em><\/strong> extracts a subarray from the nums array starting from startIdx to the third element from the end.<\/p>\n\n\n\n<\/div>\n\n\n\n