Set Range of Bits in a ushort
问题 Lets say I have a ushort value that I would like to set bits 1 to 4 inclusive (assuming 0 is the LSB and 15 is the MSB). In C++ you could define a struct that mapped out specific bits: struct KibblesNBits { unsigned short int TheStart: 1; unsigned short int TheMeat: 4; unsigned short int TheRest: 11; } Then you could assign a value to 'TheMeat' directly. I'm looking to do something similar in C#. Ideally, I would like a funcion definition that looked like this: public ModValue SetRange