Solved

c# code

Posted on 2008-10-20
3
200 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

20 Experts available now in Live!

Get 1:1 Help Now