| Subscribe via RSS

Make a positive number a negative number in 1 line of C# code – A code quiz!

July 16th, 2008 | 10 Comments | Posted in C#

Here are 4 methods, each one is meant to turn a positive number into a negative.

public int ReturnMinusVersion1(int i)
{
    return -i;
}

public int ReturnMinusVersion2(int i)
{
    return --i -i +i;
}

public int ReturnMinusVersion3(int i)
{
    return ~i + 1;
}

public int ReturnMinusVersion4(int i)
{
    return i * -1;
}

The questions are:

Which methods compile?

Which methods produce the correct result?

Explain why the working methods work.

Which is best and why?

Any other cool ways of making a positive number a negative? Have fun!

kick it on DotNetKicks.com

Microsoft Remix UK 08

July 3rd, 2008 | Comments Off | Posted in Remix08

remmix08uk "ReMix UK 08 is a 48 hr conversation; join us from the 18 – 19 September 2008 at the Brighton Centre, Kings Road, Brighton. ReMix UK 08 is all about the ‘Next Web’, what it means today and the potential impact of technologies, tools and techniques for the future. "

If you want to attend, you better get a hustle on and register as tickets are selling fast by all accounts. Last years event was fantastic and this time around it’s set to be bigger and better than ever. See you there!

  • Cloud

    Ajax AmpliFeeder ASP.NET Blabnote C# Cloud Design EntityFramework Framework JavaScript JQuery LINQ Live Mesh MicroBlog Mix07 Mobile Productivity Rails Remix08 SDS Silverlight2 SQL SSDS TDD Telecommunications Uncategorized VOIP WCF Web 2.0 Webcast


  • @jonpauldavies