Whidbey and my favorite Method…GetDateTimeFormats

I have written in the past about my favorite little method in the BCL – GetDateTimeFormats. There is only one thing that bugs me about it. You have to return an array and then get the element out of the array. For example

dim strArray() as string=now.getDateTimeFormats
dim myFavoriteFormat as string=strArray(1)
  (1 happens to be like this 1/20/03 in the en-US culture setting)

But I always want to type it like this:

dim datewithMyFavoriteFormat as string=now.getDateTimeFormats(1)

I finally got around to seeing if Whidbey does this but it doesn’t.

add: And then I wrote this post and learned that I still have  a LOT to learn about arrays – after only 20+ years of programming!! Many are happy to show me the way!!

Dim datewithMyFavoriteFormat As String = (DateTime.Now.GetDateTimeFormats())(1)

  Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!  

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.