I need to array an ad-hoc set of strings like this
string a = null;
string b = "include me";
string c = string.Empty;
string d = "me too!";
without including null or empty strings. I know I can use a child function and params
:
private List<string> GetUniqueKeys(params string[] list)
{
var newList = new List<string>();
foreach (string s in list)
{
if (!string.IsNullOrWhiteSpace(s))
newList.Add(s);
}
return newList;
}
///
return this.GetUniqueKeys(a, b, c, d).ToArray();
but is there any simpler way to do this that I'm not seeing?
EDIT: Sorry about that, happy to vote up the first LINQer, but I should have specified that I was trying to get rid of the child method altogether, not simplify it.