question

TahirAKhan-7618 avatar image
0 Votes"
TahirAKhan-7618 asked TahirAKhan-7618 commented

in this line of code if (ballout.CatchBy == ballout.PlayerName) i get this error cant be applied to operands of type 'long' and 'string'

else if (ballout.IsCatch)
{
Description = $"c {rp.FirstOrDefault(f => f.GroupId == App.GroupId && f.PlayerId == ballout.CatchBy).Name} b {ballout.PlayerName}";

                 if (ballout.CatchBy == ballout.PlayerName)
                 {
                     Description = $"c & b {ballout.PlayerName}";
                 }
             }



please help me how can i compage these ballout.CatchBy == ballout.PlayerName
what operator i should use or what type i should use for both

dotnet-csharp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DanielZhang-MSFT avatar image
1 Vote"
DanielZhang-MSFT answered DanielZhang-MSFT edited

Hi TahirAKhan-7618,
The error indicates that one of your CatchBy and PlayerName is a long type and the other is a string type. So you cannot use the "==" operator to compare strings with numbers.
so you can try use ToString() to convert the long type to a string, then compare them.
For example:

 if (ballout.CatchBy.ToString() == ballout.PlayerName)

Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.