Skip to main content
edited tags
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
edited title
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481

Better way of converting Converting a boolean list to string, and vise-versavice versa

Source Link

Better way of converting a boolean list to string, and vise-versa

I am currently using this to convert a List of booleans to a string

 var tempbllist = new List<int>(); foreach (var t in blenabled) switch (t) { case true: tempbllist.Add(1); break; case false: tempbllist.Add(0); break; } Settings.Default.blEnabled = String.Join(",", tempbllist.Select(i => i.ToString(CultureInfo.InvariantCulture)).ToList()); 

(converts them to 1s and 0s to save space)

and this to convert them back

if (Settings.Default.blEnabled.Contains(",")) blenabled = new List<bool>( Settings.Default.blEnabled.Split(',').Select(Int32.Parse).Select(i => i == 1).ToList()); 

What is a better way of doing this?