我想在工厂类中创建一个字典,用MessageId
函数映射MessageCreate
。
private Dictionary<ushort, MessageWithBody> messagesList = new Dictionary<ushort, MessageWithBody>()
{
{A1Message.getMessageId, A1Message.CreateMessage},
{A2Message.getMessageId, A2Message.CreateMessage},
};
上述删除错误导致cannot convert from method group to ushort
A1Message
和A2Message
都来自MessageWithBody
类
答案 0 :(得分:1)
更新至:
var messagesList = new Dictionary<ushort, MessageWithBody>()
{
{(ushort)A1Message.getMessageId(), A1Message.CreateMessage()},
{(ushort)A2Message.getMessageId(), A2Message.CreateMessage()},
};
您需要确保调用方法。