Last active
September 26, 2019 09:50
-
-
Save AdamRamberg/a038e38d7c5699cf7ac75d3c5e96a713 to your computer and use it in GitHub Desktop.
Delegates and Extensions in Unity - ExtensionExample.cs
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
// Defines an add method that is chainable (returns itself) | |
public static List<T> ChainableAdd<T>(this List<T> list, T item) | |
{ | |
list.Add(item); | |
return list; | |
} | |
// Usage | |
List<int> numbers = new List<int>(); | |
numbers.ChainableAdd(1).ChainableAdd(2).ChainableAdd(3); // numbers will now contain [1, 2, 3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment