置頂
LINQ問題
版上各位大神大家好
我想總結一個泛型集合
我已經有完成一段coding
但是執行時卻跑出ulong資料型態的error如下:
Items.Sum(e => e.Value);
錯誤碼如下:
Error 15 The call is ambiguous between the following methods or properties:
'System.Linq.Enumerable.Sum>(System.Collections.Generic.IEnumerable>, System.Func,float>)' and 'System.Linq.Enumerable.Sum>(System.Collections.Generic.IEnumerable>, System.Func,decimal?>)
coding程式碼如下:
public class Teststuff : BaseContainer
{
public decimal CurrentTotal { get { return Items.Sum(e => e.Value); } }
public override void Add(ulong item, int amount = 1)
{
}
public override void Remove(ulong item, int amount = 1)
{
}
}
public abstract class BaseContainer
{
///
/// Pass in the owner of this container.
///
public BaseContainer()
{
Items = new Dictionary();
}
public BaseContainer()
{
Items = new Dictionary();
}
public Dictionary Items { get; private set; }
public abstract void Add(P item, int amount = 1);
public abstract void Remove(P item, int amount = 1);
}
請大大幫幫小弟
會員登入
(先登入會員才能回覆留言喔!)