I have an array of valid e-mail address domains. Given an e-mail address, I want to see if its domain is valid
string[] validDomains = { "@test1.com", "@test2.com", "@test3.com" };
string email = "test@test1.com"
Is there a way to check if email contains any of the values of validDomains without using a loop?
I would like to recommend you the following code:
HashSet.Contains Method is an O(1) operation; while array – O(n). So
HashSet<T>.Containsis extremely fast. Also,HashSetdoes not store the duplicate values and there is no point to store them in your case.MailAddress Class represents the address of an electronic mail sender or recipient. It contains mail address parsing logic (just not to reinvent the wheel).