ソースコード
public static class GenericExtensions { public static void Swap<T>( ref this T a, ref T b ) where T : struct { var tmp = a; a = b; b = tmp; } }
使用例
using UnityEngine; public class Example : MonoBehaviour { private void Awake() { int a = 1; int b = 2; a.Swap( ref b ); Debug.Log( a ); Debug.Log( b ); } }