i have a list of keyvaluepair in c# and i want to check two keys means return true if both exist in all other it's return false.
can someone tell em how i can do this through writing one statement only like my code not worked in c#
(info.Exists(x => x.Key == "user" && x.Key == "pass"))
It sounds like you want:
if (info.Any(x => x.Key == "user") && info.Any(x => x.Key == "pass"))
(I've used Any
here so that it's more general to any IEnumerable<T>
using LINQ, but you could use Exists
for List<T>
just as easily.)
Just as a fun alternative:
string[] requiredKeys = { "user, "pass" };
if (!requiredKeys.Except(info.Select(x => x.Key)).Any())
{
...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.