Right shift operator

  • Thread starter Thread starter ERE
  • Start date Start date
E

ERE

Pardon me if this has been asked a million times -- but I thought that
because of generics, the right shift operator was supposed to change with C#
2.0. I thought it was supposed to change from ">>" to "> >", to distiguish
it from nested generics.

But I've been using VS2005, and when I put in the new syntax I get an error
message, whereas the old syntax, as shown in the following code continues to
work fine. What am I missing?

Thanks,
Dan

------------------
static void Main( )
{
for (int i = 32; i > 0; )
{
i = i >> 1;
Console.WriteLine("Value: {0}", i);
}
}
 
ERE said:
Pardon me if this has been asked a million times -- but I thought that
because of generics, the right shift operator was supposed to change with C#
2.0. I thought it was supposed to change from ">>" to "> >", to distiguish
it from nested generics.

But I've been using VS2005, and when I put in the new syntax I get an error
message, whereas the old syntax, as shown in the following code continues to
work fine. What am I missing?

The right shift operator itself hasn't been changed in terms of what
you write. It's been changed in terms of what one part of the compiler
gives to the other. Instead of the parser recognising one token of
">>" it recognises two tokens, each of which is ">".
 
Pardon me if this has been asked a million times -- but I thought that
because of generics, the right shift operator was supposed to change with C#
2.0. I thought it was supposed to change from ">>" to "> >", to distiguish
it from nested generics.

But I've been using VS2005, and when I put in the new syntax I get an error
message, whereas the old syntax, as shown in the following code continues to
work fine. What am I missing?

Thanks,
Dan

------------------
static void Main( )
{
for (int i = 32; i > 0; )
{
i = i >> 1;
Console.WriteLine("Value: {0}", i);
}
}

There has been no change to what you type, right-shift is still ">>"
and right-shift assignment is still ">>=". There has been a change to
the underlying grammar to prevent the compiler treating the >> in
nested generics as if it was a right-shift. The change is only of
interest to compiler writers and does not affect the code that you
write.

HTH

rossum
 
Thanks!

Dan

Jon Skeet said:
The right shift operator itself hasn't been changed in terms of what
you write. It's been changed in terms of what one part of the compiler
gives to the other. Instead of the parser recognising one token of
">>" it recognises two tokens, each of which is ">".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top