Good Uses for Empty Array Declarations

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?

2 Comments

Comments have been disabled for this content.