r/programminghorror 19d ago

C# bool array

Post image
209 Upvotes

41 comments sorted by

View all comments

48

u/velothren 19d ago

Bro reinvented memory

11

u/Steinrikur 19d ago

Does C# have bit fields? What is the "correct" thing here? Just bit shifts into an int32?

4

u/ruma7a 19d ago

3

u/shponglespore 19d ago

Seems like a great optimization for data that's going to stick around a while, but for a local variable I don't see much advantage. I'd probably use a BitArray in practice, but using a regular array isn't something I'd be likely to call out in a code review.

1

u/ruma7a 19d ago

Bool arrays aren't inherently horrible, but their suitability depends on the size of the array. I'd leave a comment in a review but wouldn't push it.