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

后端 未结 8 2154
北恋
北恋 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条回答
  •  说谎
    说谎 (楼主)
    2021-01-04 13:35

    Can you write an iterator for Personnel.

    public static bool IsAllowed(int userID)
    {
        return (Personnel.Contains(userID))
    }
    
    public bool Contains(int userID) : extends Personnel (i think that is how it is written)
    {
        foreach (int id in Personnel)
            if (id == userid)
                return true;
        return false;
    }
    

提交回复
热议问题