Speaking in Code

Tuesday, February 12, 2008

Stumbling in F#; Fixing it WithC#

For some crazy reason, mental blind spot probably, I've been really struggling to figure out how to work with a two-column array in F#. So, I picked up my C# book and their example made it very clear how to accomplish this. The fact I was able to understand and use the C# technique makes me feel a little better, but I suppose the F# technique is probably insanely easy and I'm just overlooking it somehow.
I also don't think this code is particularly elegant; it is long and there is a low probability that there will be duplicate random numbers created, which in this program causes the bottom of the stack to be incorrectly called. I know how to overcome this problem though, and I'd probably do something about it if I decided to put this into a game.
Anyway, without further ado, here's my C# random bingo number stack creator. You can start a new C# console application in Visual Studio 2005 and just replace the contents of Program.cs with the following
UPDATE: That code just plain didn't paste correctly. It wasn't that amazing anyway. Comment me if you want a copy and I'll get it to you.

Sunday, February 03, 2008

Date Syntax for .NET

Today I discovered that .NET has some interesting new properties and methods that can be used for deriving dates, including comparisons. My requirement was to determine the number of days between two dates with a difference between a given number of months. Here's what I came up with:

iMonthCount = -6
Date.Today.Subtract(Date.Today.AddMonths(iMonthCount)).Days

This expression shows the number of days in the past six months.

Now I don't need to use the DateAdd() or DateDiff() functions any more.