I have a text file with formatting similar to the following:
#
example1.com;example2.com;example3.com
example4.net;example6.org
example7.uk;example8.io;ab123example4.net
#
Each line defines domains owned by a single company. Each line can have 2 or more domains.
Unfortunately I cannot modify the formatting of the file.
I am not overly familiar with c# (I generally work with bash/sh on Linux/Unix where I would likely default to using grep) and am trying to extend some existing c# software to add a check whether two domains are owned by the same company.
At present I'm reading the file as follows:
private List<string> _CompanyOwnedDomains;
private String CompanyOwnedDomainsFileName = Environment.GetEnvironmentVariable(
"DomainChecker",
EnvironmentVariableTarget.Machine) +
@"Path\To\CompanyOwnedDomains.config";
// Various error checking happens here
_CompanyOwnedDomains = File
.ReadAllLines(CompanyOwnedDomainsFileName)
.Where(line => !String.IsNullOrEmpty(line))
.Where(line => !line.StartsWith("#"))
.Select(line => line.ToLower())
.ToList();
When I get to the check, so far I am a bit stuck on how to interact with the above.
For arguments sake, lets say I have two variables, DomainA and DomainB. I would like to check if both domains are owned by the same company.
I could do something like the following, however this seems quite inefficient:
var Match = _CompanyOwnedDomains
.FirstOfDefault(DomainsList => DomainsList.Contains(DomainA.ToString());
if(Match != null) && Match.Contains(DomainB.ToString())
{
// Do stuff
}
Is there a way to check if both values exist within the same list item?
Would the Contains method return ab123example4.net for a query of "example4.net" or similar?
Would I be better using a different variable type such as a dictionary?