There are two arrays list1 and list2. With LINQ you need to get an array of list3 consisting of a given number. items from list1 and given count. items from list2

    1 answer 1

    Take advantage of the features:

    • Concat () , which combines two sequences into one.
    • Take () , which allows you to return the first N elements from the sequence

    for example

    var list1 = new List<string>() { "1", "2", "3", "4", "5", "6", "7" }; var list2 = new List<string>() { "1", "2", "3", "4", "5", "6", "7" }; var list3 = list1.Take(5).Concat(list2.Take(3)); 

    As a result, list3 will contain 5 items from the first list, and 3 items from the second one.

     "1", "2", "3", "4", "5", "1", "2", "3" 

    If you want to take from lists not the first elements, but 'elements somewhere from the middle of the list, then the Skip () function will help you, which allows you to skip N number of elements from the beginning of the sequence

     var list3 = list1.Skip(2).Take(5).Concat(list2.Take(3)); 

    Result in list3

     "3", "4", "5", "6", "7", "1", "2", "3"