Shorthand conditional in C# similar to SQL 'in' keyword

后端 未结 8 2208
北恋
北恋 2021-01-04 12:44

In C# is there a shorthand way to write this:

public static bool IsAllowed(int userID)
{
    return (userID == Personnel.JohnDoe || userID == Personnel.JaneD         


        
8条回答
  •  萌比男神i
    2021-01-04 13:28

    Just another syntax idea:

    return new [] { Personnel.JohnDoe, Personnel.JaneDoe }.Contains(userID);
    

提交回复
热议问题