Click here to Skip to main content
15,906,567 members
Home / Discussions / C#
   

C#

 
AnswerRe: tlbimp.exe and Ildasm.exe? Pin
monrobot131-Apr-03 4:28
monrobot131-Apr-03 4:28 
GeneralRe: tlbimp.exe and Ildasm.exe? Pin
econner1-Apr-03 4:37
econner1-Apr-03 4:37 
GeneralRe: tlbimp.exe and Ildasm.exe? Pin
econner1-Apr-03 4:53
econner1-Apr-03 4:53 
GeneralRe: tlbimp.exe and Ildasm.exe? Pin
monrobot131-Apr-03 5:38
monrobot131-Apr-03 5:38 
GeneralBitwise operations Pin
zoltan_ie1-Apr-03 2:16
zoltan_ie1-Apr-03 2:16 
GeneralRe: Bitwise operations Pin
Jim Stewart1-Apr-03 4:15
Jim Stewart1-Apr-03 4:15 
GeneralRe: Bitwise operations Pin
monrobot131-Apr-03 4:23
monrobot131-Apr-03 4:23 
GeneralRe: Bitwise operations Pin
James T. Johnson1-Apr-03 6:58
James T. Johnson1-Apr-03 6:58 
I think an enum is better suited for this, after all you are grouping a series of constants that can all be used for the same thing.

Also, in C# a long is 64-bits and ints are 32-bits so you probably won't need a ulong (judging by your code anyway).

Now a little code:
[Flags()]
public enum VolatilityDisplay
{
  Performance = 1,
  StandardDeviation = 2,
  ArithmeticMean = 4,
  EfficiencyIndex = 8,
  Sharpe = 16,
  Variance = 32,
  Alpha = 64,
  Beta = 128,
  Treynor = 256
}
Just a quick note about the [Flags()] bit. This is basically telling the framework that the values in this enum can be used in bitwise operations. Now to get on with the rest of your question.

VolatilityDisplay value = VolatilityDisplay.Performance | VolatilityDisplay.Sharpe;
 
if( (value & VolatilityDisplay.Sharpe) != 0 )
{
  /* do something */
}
Two important things to note here:

1) When you wish to set two different bits you should use the bitwise-or (|)operator and not addition. The reason is that the addition won't do what you think if the bit is already set.

Take for example the bitvector set to VolatilityDisplay.Performance | VolatilityDisplay.StandardDeviation the integer representation of this is 3. Now you want to make sure that VolatilityDisplay.Performance is set. If you use the addition operator (+) then you are really performing 3 + 1 = 4, which if you look at the meaning of 4 in the list above it comes out as VolatilityDisplay.ArithmeticMean. Now neither of the values you wanted are set and one you didn't want is set.

2) The second part is that unlike C/C++, if statements require whatever you are testing to actually be a bool and not simply a zero/non-zero value. So you have a couple of different options, the one I used above, which is just testing to ensure a non-zero value was returned. The other is the one that someone else suggested which is to use Covert.ToBoolean. Both do pretty much the same thing, so its up to you which you want to use.

Hope that clears some things up for you,

James

"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation

QuestionHow To Use COM DLL in POcketPC application Pin
Member 3187921-Apr-03 2:15
Member 3187921-Apr-03 2:15 
GeneralMessageBox Buttons Pin
Mazdak1-Apr-03 0:49
Mazdak1-Apr-03 0:49 
GeneralRe: MessageBox Buttons Pin
James T. Johnson1-Apr-03 7:27
James T. Johnson1-Apr-03 7:27 
Generalmulti threaded client Pin
novice.NET1-Apr-03 0:18
novice.NET1-Apr-03 0:18 
GeneralRe: multi threaded client Pin
Le centriste1-Apr-03 10:01
Le centriste1-Apr-03 10:01 
Generalweb reference Pin
novice.NET1-Apr-03 0:14
novice.NET1-Apr-03 0:14 
QuestionIs this impossible ? Pin
Smitha Nishant31-Mar-03 23:32
protectorSmitha Nishant31-Mar-03 23:32 
AnswerRe: Is this impossible ? Pin
James T. Johnson1-Apr-03 7:15
James T. Johnson1-Apr-03 7:15 
GeneralRe: Is this impossible ? Pin
Smitha Nishant1-Apr-03 20:50
protectorSmitha Nishant1-Apr-03 20:50 
GeneralGetting a web browsers url Pin
ferdeen31-Mar-03 20:47
ferdeen31-Mar-03 20:47 
QuestionPlace button on form title? Pin
wei_xiang31-Mar-03 14:49
wei_xiang31-Mar-03 14:49 
GeneralInserting a tabpage Pin
monrobot1331-Mar-03 14:32
monrobot1331-Mar-03 14:32 
GeneralRe: Inserting a tabpage Pin
Chris Jobson1-Apr-03 8:14
Chris Jobson1-Apr-03 8:14 
GeneralRe: Inserting a tabpage Pin
monrobot131-Apr-03 13:38
monrobot131-Apr-03 13:38 
Generalusing references across servers Pin
novice.NET31-Mar-03 9:11
novice.NET31-Mar-03 9:11 
GeneralRe: using references across servers Pin
SimonS1-Apr-03 7:23
SimonS1-Apr-03 7:23 
Generalobject doing remoting Pin
novice.NET31-Mar-03 9:01
novice.NET31-Mar-03 9:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.