9

I can't find any direct function (like mybytearray.copy(offset, count)) that select range of bytes from byte array. So, do I have to loop through to copy required bytes?

1
  • Wait, wait. Do you want to specifically select a range from byte array, or copy a range from byte array to another array? Commented Jul 10, 2013 at 13:54

3 Answers 3

14

Dependent on what you exactly need, you might want to use LINQ. The syntax is self explaining :)

var newArr = currentArray.Skip(4).Take(300).ToArray();
Sign up to request clarification or add additional context in comments.

3 Comments

@Chris_web what do you mean with "doesn't work"? If it doesn't compile, you should add using System.Linq; first :). Which .NET version do u use?
:) here my requirement is, from a 1024byte array, I have to copy 300bytes starting from 5th byte.
I believe this should be accepted answer! It doesn't need to create a new array and works perfectly !
12

You can use Buffer.BlockCopy or Array.Copy.

Comments

1

You can use Buffer.blockcopy. link here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.