• Status: Solved
• Priority: Medium
• Security: Public
• Views: 290

C# operator

Hi,
I want to use OR Operator  .. I am not getting it correctly

int KM = 0;
rows[0]["StudentID"] =  rows[0]["studentID"]  | int.Parse(Km.ToString());
0
dotnet0824
1 Solution

Billing EngineerCommented:
can you clarify what exactly you want to achieve? (ie not how)?
0

Commented:
Hello dotnet0824,

what do you want to do?

Regards,

xRalf
0

Commented:
The or operator there would be doing a binary or http://en.wikipedia.org/wiki/Bitwise_operation

From looking I am not sure if this is what you actually want. Can you explain what you are hoping to have happen here?

Cheers,

Greg
0

Author Commented:
yep ur right.. If checkBox is checked it takes the binary value
0

Commented:
Is rows[0]["StudentID"] integer?

int a = 100;
int b = 110;
int c = a|b;

this gives me 110 as expected.

Try changing your code to this

int val = Int32.Parse( rows[0]["studentID"]);

int val = val | KM;

rows[0]["studentID"] = Convert.ToString(val);

0

Commented:
int Km = 0;
rows[0]["StudentID"] =  rows[0]["studentID"]  | int.Parse(Km.ToString());

this is the equivalent of a nop as Km is always 0... anything | 0 = anything

beyond that you could simplify this further with

rows[0]["StudentID"] |= Km;

assuming that rows[0]["StudentID"] is an integer which its impossible to tell from your code example.

Cheers,

Greg
0

Featured Post

Tackle projects and never again get stuck behind a technical roadblock.