How to Cast an ArrayList to an Array

So you have an ArrayList of strings and you want to return it as a string[] array. It's really easy:

return (string[])arrayList.ToArray(typeof(string));

Commercial Template: Six-Oh-Six

Commercial Template Six Oh Six Screenshot

Here it is! My first commercial template! :-) It costs $50.00. Until I can get PayPal working with my template, e-mail me if you want the template. :-)

using Female = Earth. LivingBeings. HomoSapiens. Female;

If you didn't know the using statement given in the title is valid, then congratulations! Now you do. ;-)

Why would you use this instead of the more general using Earth.LivingBeings.HomoSapiens.Female? Well:

To Avoid Conflicting Class Names

Suppose you Autopsy.cs uses both Earth.LivingBeings.Humans.Female as well as the Earth.LivingBeings.Monkeys.Female classes. One way to resolve the naming conflict is to laborously type out the fully-qualified class name each time you use it. The other way is to:


using HumanFemale = Earth.LivingBeings.Humans.Female;
using MonkeyFemale = Earth.LivingBeings.Monkeys.Female;

How to Send Authenticated SMTP E-mail


protected void Page_Load(object sender, EventArgs e)
{
 try
 {
  MailMessage message = new MailMessage(
    "from@example.com", 
    "to@example.com", 
    "Some Important Message", 
    "This is a test message and it's not that important.");

SmtpClient client = new SmtpClient("your.smtp.server.com");

System.Net.NetworkCredential credentials = new System.Net.NetworkCredential( "username", "password");

client.UseDefaultCredentials = true;

client.Credentials = credentials;

client.Send(message); }

catch (Exception ex) { Response.Write("Whoops! Couldn't send the e-mail: " + ex.ToString()); } }

iTunes 7 Screenshots

iTunes Screenshot from Apple

I updated to iTunes 7 this morning to find that the user interface got even better than before. Take a look: iTunes Screenshot

iTunes Screenshot

iTunes Screenshot

iTunes Screenshot

iTunes Screenshot

iTunes Screenshot

SQL Server: How Many Times Does a Word Appear in a Sentence

This is, of course, ridiculously easy to do in almost any programming language on the market these days. But what if you want to do this in SQL Server? SQL Server doesn't provide a function for this, so we'll have to create our own. The most intuitive way to do it is to simply split the given phrase by whitespace and compare each word to the word that you want to search. But this is, of course, slow, especially as the phrase gets big.

I found a nice little function in the book Beginning ASP .NET 2.0 E-Commerce in C# 2005 by Christian Darie and Karli Watson. What they do is replace each instance of the word with a word that is one character longer. Then, the length of the new sentence - the length of the old sentence will give you the number of times the word appeared in the sentence.

An example:

  • The word: "word"
  • The sentence: "The word we're looking for is the word 'word.'"
  • The replaced sentence: "The wordx we're looking for is the wordx 'wordx.'"
  • Difference in lengths of the two sentences: 3, which is the number of times the word appears.

Pretty neat. ;-)

The reason to use the REPLACE function instead of doing it the normal way, of course, is because REPLACE is faster. The code, then, which I'm copying almost verbatim from page 174 of the book:


CREATE FUNCTION dbo.WordCount(

@Word VARCHAR(20), @Phrase VARCHAR(1000))

RETURNS SMALLINT

/* @BiggerWord is a string one character longer than @Word */ DECLARE @BiggerWord VARCHAR(21) SELECT @BiggerWord = @Word + 'x'

/* Replace @Word with @BiggerWord in @Phrase */ DECLARE @BiggerPhrase VARCHAR(2000) SELECT @BiggerPhrase = REPLACE (@Phrase, @Word, @BiggerWord)

/* The length difference between @BiggerPhrase & @Phrase is the number we're looking for */ RETURN LEN(@BiggerPhrase) - LEN(@Phrase)

How To Copy Files from Your iPod to Your Local Hard Drive

The website's going to be down shortly as I upgrade my blogging software.

YamiPod Screenshot

There are several perfectly legitimate reasons for why you might want to copy files from your iPod. It could be for backup. Or it could be that you want to be able to listen to music at work even if you forget your iPod at home. Unfortunately, iTunes doesn't let you copy the files from your iPod to your local computer (which is, in my opinion, perfectly ridiculous -- you don't know how many times I ranted at an otherwise good application for exactly this reason).

Enter YamiPod Yamipod is a free iPod manager for Mac OS X or Linux or Windows. It doesn't even require an installation (on Windows, at least); it runs straight out of the box.

YamiPod Copy Screenshot

One Penny Wordpress Theme

One Penny Wordpress Theme Preview

ThemePorter contacted me recently regarding porting my templates over to Wordpress. OnePenny is now available. :-)

13 of 19 pages « First  <  11 12 13 14 15 >  Last »

On the Side