小编典典

如何修复运算符'=='对于ulong和long类型的操作数不明确

sql

我目前正在Discord Server中构建一个新命令,并且正在努力将UserId转换回服务器中的Users Nickname。

我收到错误消息运算符’==’在ulong和long类型的操作数上不明确

有人可以帮我弄清楚我做错了什么

Int64 memberId = reader.GetInt64(0);
string name = Context.Guild.Users
    .Where(x => x.Id == memberId)
    .First()
    .Nickname != null 
        ? Context.Guild.Users.Where(x => x.Id = memberId).First().Nickname 
        : Context.Guild.Users.Where(x => x.Id = memberId).First().Username;
Int64 votes = reader.GetInt64(2);
GOTWVote.Add($@"{name} has received {votes} vote(s)");

阅读 182

收藏
2021-04-15

共1个答案

小编典典

第一步是强制转换以解决歧义运算符。接下来,重新安排您的查询以摆脱两个额外的子查询:

Int64 memberId = reader.GetInt64(0);
var user = Context.Guild.Users
    .Where(x => x.Id == (UInt64)memberId)
    .First();

string name = 
    user.Nickname != null 
        ? user.Nickname 
        : user.Username;

Int64 votes = reader.GetInt64(2);
GOTWVote.Add($@"{name} has received {votes} vote(s)");
2021-04-15