I was looking for a way, how to set specific values for specific range in an array.
Something like this
Pseudocode:
var s = new uinit[64];
s[ 0..15] := { 2, 4, 6, 3, 1, 7, 8, 9, 7, 11, 37, 32, 19, 16, 178, 2200 }
s[16..31] := ...
I was trying to find something like this in C#, but with no luck. I am trying to come with something like this:
public void SetArrayValues(int startIndex, uint[] values)
{
var length = values.Length;
this.array[startIndex, startIndex + length] = values;
}
only thing I was able to find was System.Array.SetValue but this does not meet my requirements.
Am I missing something?
Thanks for any help in advance
We can change the contents of array in the caller function (i.e. test_change()) through callee function (i.e. change) by passing the the value of array to the function (i.e. int *array).
The indices for a 100 element array range from 0 to 99.
Array-slicing is supported in the print and display commands for C, C++, and Fortran. Expression that should evaluate to an array or pointer type. First element to be printed. Defaults to 0.
I think the closest you can do is via Array.Copy
:
var s = new uint[64];
uint[] values = { 2, 4, 6, 3, 1, 7, 8, 9, 7, 11, 37, 32, 19, 16, 178, 2200 };
int sourceIndex = 0;
int destinationIndex = 0;
Array.Copy(values, sourceIndex , s, destinationIndex , values.Length);
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