我有這段代碼來計算某個高度的最常見出現。但是,我似乎不能這樣做,因為以下錯誤很明顯。誰能告訴我如何解決這個問題?輸入變數lines的型別為IEnumerable<(Vector4D, Vector4D)>。
Error CS0411 The type arguments for method
'Enumerable.GroupBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>, IEqualityComparer<TKey>?)'
cannot be inferred from the usage. Try specifying the type arguments explicitly.
lines.Select(line => (Y: line.Item1.Y, Vector: line.Item1 - line.Item2))
.Where(pair => Math.Abs(Vector4D.DotProduct(new Vector4D(1, 0, 0, 0), pair.Vector)) > 0.9)
.GroupBy(pair => pair.Y, new CompareWithTolerance((float)verticalTolerance))
.Select(group => (Y: group.Key, Length: group.Sum(x => x.Vector.Length))
.OrderByDescending(pair => pair.Y * pair.Length));
internal class CompareWithTolerance : EqualityComparer<float>
{
private float _tolerance;
public CompareWithTolerance(float tolerance)
{
_tolerance = tolerance;
}
public override bool Equals(float a, float b)
{
return Math.Abs(a - b) < _tolerance;
}
public override int GetHashCode(float f)
{
return f.GetHashCode();
}
}
uj5u.com熱心網友回復:
根據我收到的反饋,我似乎忘記將比較值的型別更改為浮點數,這導致它拋出錯誤。
我在回復中提出的由此產生的問題很容易通過放置一些額外的括號來解決。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/494207.html
