Solved

C# operator

Posted on 2008-10-20
6
269 Views
Last Modified: 2013-12-17
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
Comment
Question by:dotnet0824
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22758266
can you clarify what exactly you want to achieve? (ie not how)?
0
 
LVL 6

Expert Comment

by:xRalf
ID: 22758284
Hello dotnet0824,

what do you want to do?

Regards,

xRalf
0
 
LVL 37

Accepted Solution

by:
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

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

Expert Comment

by:TechTiger007
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

by:gregoryyoung
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with Query not working in client's PC 1 35
Error in script 11 46
C# parent child form 5 17
execute SQL Stored Procedure 1000 times from vb.net 3 22
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now