Created
June 4, 2017 14:52
-
-
Save RetiredQQ/bbe1ffea5fee87d76af3d9bce8a41565 to your computer and use it in GitHub Desktop.
Initialize and delete array elements.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Arrays { | |
public static T[] InitializeWithDefaultInstances < T > (int length) where T: new() { | |
T[] array = new T[length]; | |
for (int i = 0; i < length; i++) { | |
array[i] = new T(); | |
} | |
return array; | |
} | |
public static void DeleteArray < T > (T[] array) where T: System.IDisposable { | |
foreach(T element in array) { | |
if (element != null) | |
element.Dispose(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment