How can be add Array Items to List Without Loop

I want to add/append Array Items To a List Variable without for loop.

I am using a for loop to get Array items and need to add array items to a List without using for loop as it will be 2 for loops inside of another.

find some samples here:

 arrValues
 string[3] { "C", "E", "F" }
 arrValues = arrValues.Append("G").toArray
 string[4] { "C", "E", "F", "G" }
 arrValues
 string[4] { "C", "E", "F", "G" }
 arrValues = arrValues.Prepend("B").toArray
 string[5] { "B", "C", "E", "F", "G" }
 ValuesList = arrValues.ToList
 List<string>(5) { "B", "C", "E", "F", "G" }
 ValuesList = ValuesList.Prepend("A").ToList
 List<string>(6) { "A", "B", "C", "E", "F", "G" }
 ValuesList
 List<string>(6) { "A", "B", "C", "E", "F", "G" }
 arrValues = ValuesList.Append("H").ToArray
 string[7] { "A", "B", "C", "E", "F", "G", "H" }
 arrValues
 string[7] { "A", "B", "C", "E", "F", "G", "H" }

And dor concating Lists/Arrays

grafik

 arrValues
 string[2] { "D", "E" }
 ValuesList
 List<string>(3) { "A", "B", "D" }
 ValuesList = ValuesList.Concat(arrValues).ToList
 List<string>(5) { "A", "B", "D", "D", "E" }

Thank you…Got the solution
Can we remove duplicates in case if already item exist in List ?

grafik
ValuesList = ValuesList.Distinct().ToList
List(4) { “A”, “B”, “D”, “E” }

Thank you

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.