Last active
June 15, 2023 08:00
-
-
Save megasuperlexa/c70b5c171e243abb01963bf2bf09f407 to your computer and use it in GitHub Desktop.
enums as ID markers C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
BadMethod(1,2); | |
BadMethod(2,1); // bang! | |
GoodMethod(2,1); // tadam | |
var uid = (UserId)1; | |
var accid = (AccountId)2; | |
GoodMethod(uid, accid); | |
GoodMethod(accid, uid); // tadam | |
void BadMethod(long user, long account) | |
{ | |
} | |
void GoodMethod(UserId user, AccountId account) | |
{ | |
} | |
enum UserId:long{}; | |
enum AccountId:long{}; | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment