在C#中引用数组的一部分 [英] Referencing a part of an array in C#

查看:425
本文介绍了在C#中引用数组的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一些数据的数组,比如一个头和一个真实的数据。我需要传递数组中包含的数据到一个方法,但我绝对要避免将其复制到另一个数组。

I have got the array containing some data, say, a header and a real data. I need to pass the data contained in the array to a method, but I definitely want to avoid copying it to another array.

我想到的东西像ArraySegment,但它似乎在我的情况不工作(或者我错了?)。

I thought of something like ArraySegment, but it seems not to work in my case (or maybe I'm wrong?).

那么,如何将数组的一部分传递给方法,因为它是一个数组本身?

So, how to pass a part of an array to a method, as it was an array itself?

感谢您的回复!

干杯

推荐答案

跳过 Take

var subArray = array.Skip(5).Take(10);

这篇关于在C#中引用数组的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆