How to convert a list into a string? How to convert a list into a string? selenium selenium

How to convert a list into a string?


You could just use string join. I haven't checked this in visual studio, but it should work.

var passengersList = string.Join(", ", _passengerDetails.GetPassengerNames());


Try this code

var resultString = string.Join(",", passengersList);


The code that you are using to add the list to the session is correct, if you want to retrieve the same from session means you have to use the following lines, instead for saving as a concatenated string, retrieving them and split to get the values. try this:

var passengerList = (List<string>)ScenarioContext.Current["PassengersList"];// If you want them as a comma separated values thenstring csvPassengerList = String.Join(",",passengerList);

Please note: [Reference]

Session variables can be any valid .NET Framework type. The value returned by session variable must be cast to the appropriate type when you retrieve it from the SessionStateItemCollection.