Skip to content

Instantly share code, notes, and snippets.

@AceAce2025
Created June 4, 2017 14:52
Show Gist options
  • Save AceAce2025/bbe1ffea5fee87d76af3d9bce8a41565 to your computer and use it in GitHub Desktop.
Save AceAce2025/bbe1ffea5fee87d76af3d9bce8a41565 to your computer and use it in GitHub Desktop.

Revisions

  1. AceAce2025 revised this gist Jun 4, 2017. 1 changed file with 15 additions and 20 deletions.
    35 changes: 15 additions & 20 deletions Arrays.cs
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,17 @@
    public static class Arrays
    {
    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 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();
    }
    }
    }
    public static void DeleteArray < T > (T[] array) where T: System.IDisposable {
    foreach(T element in array) {
    if (element != null)
    element.Dispose();
    }
    }
    }
  2. AceAce2025 created this gist Jun 4, 2017.
    22 changes: 22 additions & 0 deletions Arrays.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    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();
    }
    }
    }