I am returning a list of codes called AllCodes from a SQL database. Basic schema like:
id | countrycode | refprint | refscan | reffax
1 . US . 123 . 234 . 345
I have a method which should needs to return a a value based on a matching countrycode and whatever column I need from that result.
Here is the method (not working offcourse) but not sure how to achieve this kind of thing with c#
private string GetServiceCode(string cc, string name)
{
var code = AllCodes.Where(x => x.CountryCode == cc).FirstOrDefault();
if (code != null)
{
// I want to return whatever {name} is, not code.name
// so if name = "refprint" I want to return code.refprint
return code.{name};
}
}
// Example:
GetServiceCode("US","refprint"); // Would return 123
.Select(name)