c# - Convert char Array/string to bool Array -


This field shows a true / flag flag for every day of the week in our database which looks like this: '1111110 '

I need to change this value into an array of Boolean.

For this, I have written the following code:

  char [] freqs = day of week frequency. Cochrane (); Bull [] = Days of the week enabled = new Bull [] {Convert. Toulion (free purse [0]. Toaster (), convert.Toolian (int. Purse [1] .restring ()), Convert ToBoolean (int.Parse (freqs [2]. Two string () Convert to.ToBoolean (int.Parse (freqs [5]), convert .tooboan (int. Purse [3] .restring ()), convert.Towlian (int. Purse (freeze [4] .tostring () Toast (), convert toBoolean (int.Parse (freqs [6]. ToString ())}};  

And I like this because of many conversions in this way I look for a lump .

What would be the ideal / clean way to change this fixed length string into a bull's array?

I know that you have given it a for-loop But the volume of days in a week will never change and therefore I think it is a more demonstrative way to go.

A little bit of LINQ can do a very trivial task:

  var weekdaysEnabled = weekdayFrequency.Select (chr = & gt; chr == '1'). ToArray );  

Note That string is already in the IEnumerable & lt; Char & gt; , so that you can use LINQ methods directly on it.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -