[Flags] enum: sugar for working with bits - by Kirill Osenkov - MSFT

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 247537 Comments
Status Closed Workarounds
Type Suggestion Repros 2
Opened 12/21/2006 1:20:25 PM
Access Restriction Public


Imagine we have an enum:

	enum BitField
		ZeroBit = 1,
		OneBit = 2,
		TwoBit = 4,
		ThreeBit = 8

I propose some syntactic sugar to simplify working with bits.
Consider the following:

	BitField b = BitField.TwoBit | BitField.ThreeBit;

Testing bits:
	// how about this sugar?
	// bool secondBitSet = b.TwoBit;
	// instead of:
	bool secondBitSet = (b & BitField.TwoBit) == BitField.TwoBit;

Setting bits:
	// how about
	// b.TwoBit = true;
	// instead of:
	b |= BitField.TwoBit;

Same for clearing bits.

Please see also similar feedback here:

Sign in to post a comment.
Posted by Microsoft on 4/24/2008 at 4:37 PM
Thanks again for your suggestion. After having done feature planning for the next release of C# I regret to say that this feature is not being added. We have to do some harsh prioritization, both because of our implementation and testing resources, but also because we need to keep the number of new langauge features at a manageable level - depending on how you count, we are adding only four language features to C# this time around. Unfortunately many great suggestions just can't make it in because of that.

I apologize that this is a "canned" follow-up answer, sent out as a result of our feature planning for the next release. In most cases I or someone else already replied individually to your suggestion - please let us know if you feel it hasn't been adequately addressed.

Thanks again for taking the time to share your ideas with us. Please keep them coming!

Mads Torgersen, C# Language PM.
Posted by Microsoft on 2/1/2007 at 3:53 PM
Thanks for your suggestion. We carefully review all of the suggestions that we receive.

Unfortunately, at this point in the product cycle, we cannot add new features to the product. Right now, we are mainly working on raising the quality of the current feature set.

We will revisit your suggestion as we start planning for the new release.