Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
561 views
in Technique[技术] by (71.8m points)

c# - how to fix operator '==' is ambiguous on operands of type ulong and long

I'm currently building a new command in my Discord Server and i'm struggling to convert the UserId back to the Users Nickname in my server.

i am getting error message operator '==' is ambiguous on operands of type ulong and long

Could someone help me figure out what i've done wrong

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)");
question from:https://stackoverflow.com/questions/65854294/operator-is-ambiguous-on-operands-of-type-long-and-ulong

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The first step is to cast to resolve the ambiguous operator. Next, rearrange your query to get rid of the two extra subqueries:

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)");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...