-
-
Save markcastle/57f7b8c1f96628891e3a83086d39e3e3 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