locked
Select Array from Specific Index to specific Index RRS feed

  • Question

  • User-1582831422 posted

    is there any direct method or something except using loop to get array elements from speicifc index to other specific index
    like if i have array of integer that has 20 elements i want to get new array as child of that array which has elements from index 5 to index 10

    Tuesday, March 20, 2012 3:04 PM

Answers

  • User-231977777 posted

    Hi Ahmed  ,

    look at this example :-

     int[] nums = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 89, 9, 9, 10, 10, 01, 12, 4, 5, 7, 87 };
    
    int[] newarr = nums.Where((number, index) => (index > 5 && index < 10)) .ToArray();
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 20, 2012 4:26 PM

All replies

  • User-1589095703 posted

    Have you tried Copy method?

    Array.Copy Method

    Using LinQ

    Tuesday, March 20, 2012 3:46 PM
  • User-231977777 posted

    Hi Ahmed  ,

    look at this example :-

     int[] nums = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 89, 9, 9, 10, 10, 01, 12, 4, 5, 7, 87 };
    
    int[] newarr = nums.Where((number, index) => (index > 5 && index < 10)) .ToArray();
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 20, 2012 4:26 PM
  • User-1582831422 posted

    Great and thanks mister Egyptiano ;)

    Tuesday, March 20, 2012 4:39 PM