By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,084 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,084 IT Pros & Developers. It's quick & easy.

uint type can not use <<, >> operator. Why not.?

P: n/a
Ȳ
//this code generates the error.
uint a=1,b=2;
Console.WriteLine(a << b);
Console.WriteLine(a >> b);

What problem does "uint type" have.?
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Ȳ <jh******@chol.com> wrote:
//this code generates the error.
uint a=1,b=2;
Console.WriteLine(a << b);
Console.WriteLine(a >> b);

What problem does "uint type" have.?


The shift operators are as follows:

int operator <<(int x, int count);
uint operator <<(uint x, int count);
long operator <<(long x, int count);
ulong operator <<(ulong x, int count);

int operator >>(int x, int count);
uint operator >>(uint x, int count);
long operator >>(long x, int count);
ulong operator >>(ulong x, int count);

Note that the second parameter is *always* an int, never a uint.

So, if you change your code to:

uint a=1;
int b=2;
Console.WriteLine(a << b);
Console.WriteLine(a >> b);

it should be fine.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.