我有一个类,它提供一个公共方法,即当前set和传递的set之间的Dice set操作作为参数。我读过很多关于Lambda的文章,并想知道如何做到这一点?
public float FindDice(Set<T> other) =>
(((float) (2 * this.Intersect<T>(other).Count<T>())) / ((float) (this._count + other.Count)))
然而,这不适用于c#,任何人都可以用一些理论向我解释为什么?
答案 0 :(得分:0)
C#与C ++不同,作为一个工作示例,你可以做这样的事情
Func<HashSet<int>, HashSet<int>, float> findDice = (HashSet<int> a, HashSet<int> b) => { return (float)(a.Intersect<int>(b).Count<int>() / (float)(a.Count + b.Count)); };
现在findDice
是一个名为lambda的函数。