February 28th, 2014, 09:20 AM
If else statement Question
I have been trying to get this to work for a while now and just to new to fully understand what is the problem.
I'm using a OS class, that I found on the internet.
What I do not understand is what I need to do to make this If else statement work with this above code.
static public SoftwareArchitecture ProgramBits
SoftwareArchitecture pbits = SoftwareArchitecture.Unknown;
System.Collections.IDictionary test = Environment.GetEnvironmentVariables();
switch (IntPtr.Size * 8)
pbits = SoftwareArchitecture.Bit64;
pbits = SoftwareArchitecture.Bit32;
pbits = SoftwareArchitecture.Unknown;
This is the error message that I get when I use 64 and 32.
private void button2_Click(object sender, EventArgs e)
if (OSVersionInfo.OSBits == 64)
MessageBox.Show("OS is x64 Bit");
else if (OSVersionInfo.OSBits == 32)
MessageBox.Show("OS is x86 Bit");
When I Debug, this is the error message that I get "Error 1 Operator '==' cannot be applied to operands of type 'JCS.OSVersionInfo.SoftwareArchitecture' and 'int' D:\OSVersionInfo\OSVersionInfo\Form1.cs 45 17 OSVersionInfo
This is the error message that I get when I switch it to Bit64 and Bit32
Error 1 The name 'Bit64' does not exist in the current context D:\OSVersionInfo\OSVersionInfo\Form1.cs 45 41 OSVersionInfo
Any help to learn what I'm doing wrong would be great.
March 1st, 2014, 01:59 PM
Re: If else statement Question
What type is the property OSBits. If it isn't an integer like the values 32 and 64 can be then you will see the compiler error you are seeing. To find out what type it is, put your mouse over the .OSBits property, right-click and choose "go to declaration".
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!