Solved

C# operator

Posted on 2008-10-20
6
273 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 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