Skip to content

Instantly share code, notes, and snippets.

@DamianSuess
Created June 8, 2019 03:59
Show Gist options
  • Save DamianSuess/a61125315a1e8b3a73940c2a2c882212 to your computer and use it in GitHub Desktop.
Save DamianSuess/a61125315a1e8b3a73940c2a2c882212 to your computer and use it in GitHub Desktop.
public static class ListExtension
{
public static void Add<T>(this List<T> list, T value, out List<T> newInstance)
{
if (list == null) list = new List<T>();
list?.Add(value);
newInstance = list;
}
}
[Test]
public void ListAddTest()
{
List<string> list = null;
list.Add("test",out list);
Assert.AreEqual(1,list.Count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment