我有一个枚举:

public enum PrivilegedAccounts
{
    User = 1,
    Service = 16,
    Admin = 64,
    Other = 1040,
    Executive = 2048
}


我希望赋予与用户不同的价值。
我知道有这个兰特(不确定是真的):

foo = (PrivilegedAccounts) (rand());


但是如何使除“ user”以外的任何值都值?

谢谢,

最佳答案

我希望这是您要寻找的。

public enum PrivilegedAccounts
{
    User = 1,
    Service = 16,
    Admin = 64,
    Other = 1040,
    Executive = 2048
}

 var values = Enum.GetValues(typeof(PrivilegedAccounts));
 SomeEnum randomValue = (PrivilegedAccounts)values[Random.Range(1, values.Length)]; //Start from 1 instead of 0 to avoid User

10-08 00:05