Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
重複の可能性: C# 動的演算子
可能かどうかわかりませんが、質問させてください。
たとえば、リストから簡単な数学演算を生成します
そのような
List lstMat={=,+,-}
次に、0 ~ 2 のランダムな値を生成し、そのリストからその演算子を選択します
int ir1=1; int ir2=2; int irNew= ir1 lstMat[1] ir2 ; //irNew would be 3
これは可能ですか?
私が考えることができる最も近いもの
List<Func<int, int, int>> lstMat = new List<Func<int, int, int>>() { (x,y)=>x.CompareTo(y), (x,y)=>x+y, (x,y)=>x-y }; int ir1=1; int ir2=2; int irNew= lstMat[1](ir1,ir2);