Which expression should be used to combine and display city names from two lists?
Option 2 is the right answer as it concats both the lists and then print.
String.Join(",", Enumerable.Concat(FranceCities, IndiaCities).ToList)
Option 2 seems fine
It will contact both country list and that single list country name will be seen by conman separated value @nevesisabela963 for ex
Mumbai,Pune,….
Hi @nevesisabela963 ,
String.Join(“,”, Enumerable.Concat(FranceCities, IndiaCities)) is Correct one.
- Enumerable.Concat(FranceCities, IndiaCities): This combines the two lists into one enumerable collection.
- String.Join(“,”, …): This method converts the combined collection into a single string, with each city name separated by a comma.
Option 1) This will not produce a readable string of city names. ToString will return the type of the list, not its content.
Option 3)This will concatenate the type names (e.g., “System.Collections.Generic.List`1”) rather than the actual city names.
Option 4)Similar to the first option, this will return the type of the enumerable, not the content.
