C# 3 Conversion Extension Method Library 1.0
If you have had a chance to muck around with the new language features of C# 3 in the latest beta of Orcas, I’m sure you will be as much of a fan of extension methods as I am. The ability to package little ‘lumps’ of functionality and add them onto objects that I use every day is a lot of fun.
I use the .ToString() method habitually so I thought I’d build a little library to perform some other .ToWhatever methods on some of the basic datatypes. So for example, the String datatype has .ToBool, .ToInt32, . ToDecimal etc. extended into it. The int32 datatype has .ToChar, .ToFloat etc. etc. It’s a nice little utility class that I hope you will find of some use. Download it and have a little dig around to see what the library is capable of.
Also, I’ve added in a couple of string manipulations as extensions too.
To reverse a string we have string.Reverse, to proper case a string we have string.ProperCase ( so for example, “jon davies” becomes “Jon Davies” ). I’ve also added string.Left and string.Right extensions, just because VB has them and C# doesn’t!! string.Left(3) returns the first 3 characters in a string, string.Right(3) returns the last 3.
Anyway, it was a lot of fun writing this – I’m going to keep adding new useful extensions to the library, so don’t forget to bookmark this site and keep an eye out for updates.
Edit: I’ve changed the name of the article thanks to the advice of posters on DotNetKicks and James to be 3.0 centric not 3.5. Apparently there is a bit of confusion as to the naming of the new updates, so it’s the .NET framework 3.5 and C# 3. Thanks for the tip off!

