Re: << and >> operators in c#




Stephany Young wrote:
arrayOfLines << new string( "another line" ) ; // adds to the end
of the array
databaseTable << row ; // adds a row to the database table

the general rule being:
<< adds to something
= replaces the contents of something with something else.

And what language might that be defined in?

a great language. one that also allows the programmer to define the
types that a class can be implicitly converted to. that is a feature
C# could benefit from. I dont like casting.


I have not used bit shifting for years. If you are looking to multiply

Just because you personally have not used a powerful element of the language
for years, don't assume that other people don't use it regularly.

what do they use it for? I think it makes a poor bit shift because it
ties you too close to the byte size of what is being operated on and
the unit of measure is implied as bits. why not a syntax that allows
you to shift by bits, bytes, characters?
wordValue = wordValue ShiftLeft 2 Bytes ;

-Steve





"Steve Richter" <StephenRichter@xxxxxxxxx> wrote in message
news:1169437733.682933.241290@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Stephany Young wrote:
Maybe you would like to expand on the 'piping and 'adding' bits.

arrayOfLines << new string( "another line" ) ; // adds to the end
of the array
databaseTable << row ; // adds a row to the database table

the general rule being:
<< adds to something
= replaces the contents of something with something else.

Also, what makes you think that bit-shifting is seldom used?

I have not used bit shifting for years. If you are looking to multiply
or divide, better to use those operators. ( and the optimized compilers
of today likely bit shift when we multiply by a constant that is a
power of 2. )

-Steve






"Steve Richter" <StephenRichter@xxxxxxxxx> wrote in message
news:1169429467.473348.39610@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Ben wrote:
Hi,

I'm trying to figure out the purpose of these operators.
Now, I know what they do. They shift bits either left or right.
But I don't know why would anybody want to do that. I've never seen
anyone using it in his/her code.
Any ideas?

it is a tragic mistake that an operator that is tailor made for piping
and adding to lists, is reserved instead for such a trivial, seldom
used operation. If you want to shift bits, better to have a new literal
operator:
bunchOfBits shiftleft 2 ;

-Steve



.



Relevant Pages

  • Re: << and >> operators in c#
    ... of the array ... the general rule being: ... Just because you personally have not used a powerful element of the language ... They shift bits either left or right. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Shift em bits
    ... The language won't allow it. ... Shift operators only apply to integer ... you might find that you have defined an "8 uchar array" as your ... If you really are trying to write portable code (avoiding ASM for ...
    (comp.arch.embedded)
  • Re: << and >> operators in c#
    ... Stephany Young wrote: ... of the array ... the general rule being: ... They shift bits either left or right. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Packages and returning errors
    ... > array intact. ... sub is_a_instance_method { ... my $class = shift; ... You need to fix the scope of $error by moving its declaration outside ...
    (comp.lang.perl.misc)
  • Re: Packages and returning errors
    ... The perldoc function guide says about shift (which is ... "Shifts the first value of the array off and returns it, ... If an array of values are passed to a sub, ... Back to my package (which I am currently thinking might be out of my depth, ...
    (comp.lang.perl.misc)