Solved

# C# operator

Posted on 2008-10-20
279 Views
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
Question by:dotnet0824
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 143

Expert Comment

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

LVL 6

Expert Comment

ID: 22758284
Hello dotnet0824,

what do you want to do?

Regards,

xRalf
0

LVL 37

Accepted Solution

gregoryyoung earned 125 total points
ID: 22758289
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 Comment

ID: 22758358
yep ur right.. If checkBox is checked it takes the binary value
0

LVL 13

Expert Comment

ID: 22758451
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

LVL 37

Expert Comment

ID: 22761335
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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Securing WEBAPI on Azure 2 55
VB.Net Developer - Suggestions for Web Programming OnLine Learning 4 59
asp.net repeater server posting 5 35
What are MicroServices? 4 67
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
###### Suggested Courses
Course of the Month7 days, 22 hours left to enroll