You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cast.cs 446 B

123456789101112131415
  1. public async Task MessageReceivedHandler(SocketMessage msg)
  2. {
  3. // Option 1:
  4. // Using the `as` keyword, which will return `null` if the object isn't the desired type.
  5. var usermsg = msg as SocketUserMessage;
  6. // We bail when the message isn't the desired type.
  7. if (msg == null) return;
  8. // Option 2:
  9. // Using the `is` keyword to cast (C#7 or above only)
  10. if (msg is SocketUserMessage usermsg)
  11. {
  12. // Do things
  13. }
  14. }