Skip to content

Instantly share code, notes, and snippets.

@megasuperlexa
Last active June 15, 2023 08:00
Show Gist options
  • Save megasuperlexa/c70b5c171e243abb01963bf2bf09f407 to your computer and use it in GitHub Desktop.
Save megasuperlexa/c70b5c171e243abb01963bf2bf09f407 to your computer and use it in GitHub Desktop.
enums as ID markers C#
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