Solved

C# operator

Posted on 2008-10-20
6
276 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 143

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell File Sort 8 41
Need a simple RegEx to search for two words 27 46
How to repeat the data 4 19
itextsharp with c# 3 9
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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 …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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