I am using C#, and it's rather annoying that I can't send an array starting from a certain point like in C++.
suppose this code:
int[] array = new int[32];
foobar (array + 4); //send array starting from the 4th place.
this is a weird syntax for C# because we don't have any usable pointers, but surely there's a way to do it? There's .Skip(), but I think it produces a new array, which is something I do not like.
What are my options?
You might want to pass it as an IEnumerable<int>
rather than as an array. You can then use skip and it will simply move the iterator over the number of elements skipped. Used this way, you won't have to use ToArray() and create a copy of the portion of the array in question. Of course, IEnumerable may not be appropriate for what you want to do, but that's difficult to tell from your question.
public void FooBar( IEnumerable<int> bar )
{
...
}
int[] array = new int[32];
FooBar( array.Skip(4) );
.NET has the System.ArraySegment
wrapper – unfortunately, it's completely useless since it doesn't implement IEnumerable
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With