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));
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));

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. :-)
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:
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;
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());
}
}

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






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:
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)
The website's going to be down shortly as I upgrade my blogging software.

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.


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