Solved

c# code

Posted on 2008-10-20
3
202 Views
Last Modified: 2013-12-17
there is a small prob with the code converted from vb to c#
---------visual basic ------------
dim j as integer
dim i as integer
for i =0 to 5
j = 2 ^ i    (i being 0 in first time loop)

msgbox(j) returns 1 (ie 2 ^ 0)  

next

==============cSharp========================I want this to return 1 same as in vb

but same code in C# msgbox(j) returns 2
int j = 0;

  for (int i = 0; i < 5; i++)
    {
       j = 2 ^ i;
      Messagebox.show(j); -- j returns 2 (ie  2 ^ 0)

    }
0
Comment
Question by:dotnet0824
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 22756364
Hello dotnet0824,

I believe that the ^ operator is not used in c#, you have to use Math.Power(value,exponent) instead. It is there in VB.net as it is a legacy operator from earlier versions of VB though the Math.Power function works there too!

Regards,

TimCottee
0
 
LVL 19

Expert Comment

by:alb66
ID: 22756752
In C#, ^ is the logical "exclusive or" operator

2 XOR 0 is equal to 2

http://msdn.microsoft.com/en-us/library/6a71f45d(VS.80).aspx
0
 
LVL 19

Assisted Solution

by:alb66
alb66 earned 50 total points
ID: 22756764
The correct method to use is Math.Pow(x,y)

http://msdn.microsoft.com/en-us/library/system.math.pow.aspx
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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:…
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!
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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