Solved

C# operator

Posted on 2008-10-20
6
281 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
[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
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 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