Share via


Interface Type Param Arrays to Operate on Many Objects

Here is an example:

    1: private void Dispose(params IDisposable[] disposableObjects)
    2: {
    3:     foreach (IDisposable disposableObject in disposableObjects)
    4:     {
    5:         if (disposableObject != null)
    6:         {
    7:             disposableObject.Dispose();
    8:         }
    9:     }
   10: }

I have a bunch of disposable objects that need to be cleaned up on finally.   In most cases I employ the uses construct, but not in this case

    1: finally
    2: {
    3:     Dispose(projectServer, currentTimesheet, previousTimesheet, classifications);
    4: }