I am so glad that after all these years of software development; I still find the amount I don’t know is so much more vastly great in magnitude than what I know. Nothing saddens (and scares) me more to think I would ever get to a point where there is nothing else to do and it will remain the same from here on out.

Working with .Net the last few years has been great, but there was a feature in .Net version 3.0 I missed while doing maintenance work with a ASP.NET 2.0 app. .Net Extension Methods is awesome! Jason, a new coworker ( I changed jobs a few weeks back) point me to this
http://www.codinghorror.com/blog/2008/07/monkeypatching-for-humans.html
Well, after checking this out, I decided to write a few extensions for myself and put them here.

public static string Right(this string s, int len)
{
if (len == 0 s.Length == 0)
return "";
if (s.Length <= len)
return s;
return s.Substring(s.Length -len, len);
}

public static int WordCount(this string s)
{
string[] rtn = s.Split(' ');
return rtn.Length;
}

These extensions to the string class give you an easy way to do the following:
string myString = "Hello World";
int cnt = myString.WordCount();
MessageBox.Show(cnt.ToString());
MessageBox.Show(myString.Right(5));

It just adds nice functionality and keeps code cleaner. I also seen where people add extension to classes they have built, but if you need to make an extension method to a class you control the code, why don’t you just add the method to the class and not over engineer by making extensions. However, for the string or int classes (Classes you don’t control), extensions are wonderful!

Comments

Popular posts from this blog

It is on like Donkey Kong!

Open Letter to Microsoft

Writing a Video Game