Object Reference .NET

ref this.Object

Back from holiday

clock April 18, 2008 02:36 by author Naz

Hey everyone just got back from my holiday in Bangladesh had a great time there ended up extending my holiday.

I see someones hacked the site already (Beeshup?)

Anyways here's a pic of me and some students on thier first school trip ever!



To Extension Method

clock April 4, 2008 22:35 by author Naz
Many times you find yourself having to convert the type of an object to another. The ToString() method is probably one of the most useful methods, it's great for easy conversion of objects to string, but what if you want to do it the other way round or even an int to a decimal?

Say I had a string and I wanted it to turn it into an Int32, I could just use the Convert class and do a Convert.ToInt32(myInt) but I would like to be able to do this myInt.ToInt32().

Well now you can with .NET 3.5 Extension Methods! Here's my implementation

public static T To<T>(this IConvertible s)
{
    return (T)Convert.ChangeType(s, typeof(T));
}

All objects that inherit from an IConvertible e.g. string, int, bool etc., will convert the value to the type you specify e.g.

int myInt = myInt.To<Int32>();

It works perfectly with the Visual Studio Intellisense 


kick it on DotNetKicks.com 


Why am I blogging

clock April 4, 2008 16:47 by author Naz
I've been recently asking myself "Should I blog?" it seemed to me like everyone these days is bloging about one thing or another. I've always felt like contributing but never had the courage to do anything about it until a couple of days ago when I read this interesting blog article.

http://codebetter.com/blogs/jeremy.miller/archive/2008/01/25/should-i-blog.aspx

So I decided to give it a go and here I am today writing my first blog article. I'm not the best of writers and I’m sure I’ll occasionally get things wrong but for me it's all about the experience and the chance to share what I enjoy most, coding.



RecentComments

Comment RSS

Sign in