- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Admin
Admin
lol @ the WTF there (allocating an int then incrementing it assigning an initial value;
Assuming that you did allocated b_acc and set it correctly elsewhere, I imagine something like the following would get the job done!
b_acc += (b ? 1 : 0);
This will convert the bool into an int in a clear and concise way. It would eve work under C++.
CAPTHA - veniam --- can I get that on a sandwich
Admin
Yeah, made a mistake right there.
It just came to my mind that once I had a situation in Java, in where there was a set of boolean values and I needed to count the number of trues. Of course, in Java its a grave offence even to think of cast a boolean into anything, so I did that with ternary the conditional too.
"What's the point?" You say. I just wanted to know if its possible in C# to use booleans in integer exressions.
Admin
Since it's an extension method, no need to menmtion the type in the method name...
public static string ToStr(this bool b){return b.ToString();}
Admin
Pedantic much?
Admin
MSDN clearly states Parse() is case insensitive. RTFM, noob.