In MATLAB its simple:
array1 = [5,6,7,8];
array2 = array1(2:3);
OUTPUT:
array2 = [6,7]
How do I do this in CSharp?
In MATLAB its simple:
array1 = [5,6,7,8];
array2 = array1(2:3);
OUTPUT:
array2 = [6,7]
How do I do this in CSharp?
Arrays in c# start with index 0, so doing this will give you the same output as your example.
array1 = [5,6,7,8];
array2 = new Array[array1[1],array1[2]]
OUTPUT
array2 = [6,7]
EDIT because of this comment: Might have been a bad example. What about array2 = array1(132:279) I dont want to have to write them all individually – lsama
An easy way to do it is with a method like this.
array1 = [5,6,7,8];
array2 = new Array();
private void getThisIndexes(int firstIndex, int lastIndex){
for(int i=0; i < array1.length; i++){
if(i < firstIndex&& i >= lastIndex){
array2.add(array1[i]);
}
}
}