eWorld.UI - Matt Hawley

Ramblings of Matt

Good Uses for Empty Array Declarations

February 20, 2004 17:54 by matthaw

While working on my companies new intranet, I've decided to pull some of our existing pages that are "Classic" ASP based, into the .NET realm.  In doing so, I need to gain access to our staff information from a SQL Server Database.  Since no stored procedures were ever used, and I don't have the security level to create any, I needed to build some queries that will retrieve the data I wished.

I decided that I would develop 1 Data Access Layer method that would take in a string array of departmental codes used.  This would allow my Business Logic Layer to have N number of methods that could retrieve staff data based on 1-N departments, or just retrieving all staff. Well, since I don't know all the departmental codes currently, and don't want to re-program the thing when a new department is added, I decided to make a clause in the DAL method that will execute a query with no deparment checking.

However, to do this, I needed to pass in a empty string array. To much amazement by me, the .NET framework (or maybe just C#) allowed me to do just that.  By using the code -- new string[0] {} -- I was able to compile and call the DAL method with success.  Interesting as this is, I started to think what other uses besides this do declaring empty arrays actually have.  Have you ever used this type of declaration before, if so why?

Categories: .NET
Actions: E-mail | Permalink | Comments (2) | Comment RSSRSS comment feed


February 21. 2004 00:24

Have you looked at the params keyword?


February 21. 2004 00:26

Actually no, but I'll keep that in mind for future reference.

Matt Hawley

Comments are closed

Copyright © 2000 - 2021 , Excentrics World