New Operators in .NET 4.0 ???

Posted: April 18, 2010 in C#, Programming
Tags:

There is two new operator in .NET 4.0, goes to and is approached by ( –> and <– ), Oh yeah… it is not pointer like in C++

Let see how it is working :

using System;

namespace TestNewOperator
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 10;
            while (x --> 0)
                Console.Write(x);

            Console.ReadKey();
        }
    }
}

The output is :
9876543210

using System;

namespace TestNewOperator
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 10;
            while (0 <-- x )
                Console.Write(x);

            Console.ReadKey();
        }
    }
}

The output is :
987654321






Okay…






Do you smell anything strage?






Yeah..






YOU HAVE JUST FOOLED






Of course there is not any new operators in C# 4.0. “while (x –> 0)” is the same as “while( x–   >   0 )” which is of course perfectly legal and sensible code. This is an old joke; it works in any language with a “–” decrement operator.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s