TDD with .NET - implicit conversions

By: Johnathon Wright on: December 19, 2008

Continuing the "TDD in .NET": series...

 namespace EduTest{     [TestFixture]     public class NameTests     {         [Test]         public void namecanbeimplicitlyconvertedtostring()         {             Name mick = new Name();             mick.FirstName = "Mick"             mick.LastName = "Jagger"             string micksname = mick;             Assert.Equals("Mick Jagger", micksname);          }     } }

This won't compile. It complains that "Cannot implicityly convert from type 'Edu. Name' to 'string'. We can go ahead and call this a failure.

namespace Edu{     public class Name     {         public static implicit operator string(Name n)         {             return n.ToString();         }    } }

Success. Yeah.


Just checking that you are human. What would be the result of this code?

a = 3*(4/2); b = 1; a+b