The code below is part of authorization. I am trying to mentally imaging what it actually does but could not somehow.
IsAuthorized = ((x, y) => x.Any(z => y.Contains(z)));
Could anyone explain this lambda expression to me?
Thanks!
Edit:
IsAuthorized is a delegate type. The previous programmer who code this seems want to keep it secret by putting delegate to the end of cs file.
The actual code is:
public delegate bool IsAuthorized(IEnumerable<Int32> required, IEnumerable<Int32> has);
IsAuthorized = ((x, y) => x.Any(z => y.Contains(z)));
Sure – it’s saying given a pair
(x, y), doesxcontain any values such thatycontains that value.Looks to me like it’s really saying “is there any intersection between
xandy“.So an alternative would probably be:
It’s just possible that that wouldn’t work, depending on the type of
IsAuthorized, but I expect it to be correct.