Say there are two arrays:
String[] title = { \"One\",\"Two\",\"three\",\"Four\"};
String[] user = { \"rob\",\"\",\"john\",\"\"};
I need to
In looking at Marc's answer (and ultimately the Zip method as of .Net 4), there is a significant amount of overhead to enumerate and join of rows where they are eventually thrown away; can that be done without that waste?
In looking at Jon's answer, creating a projection of dynamic entities to reference the existing data and then creating a new set of entities from that mirror could be a deterrent to using that method if the total row count were overly large.
The below snippet uses the references to the original data and the only wasted projected entitles created are the ones which have null string which are subsequently removed. Also the enumeration of the data is kept to a minimum.
String[] title = { "One","Two","three","Four"};
String[] user = { "rob","","john",""};
user.Select ((usr, index) => string.IsNullOrEmpty(usr)
? string.Empty
: string.Format("{0}:{1}", title[index], usr ))
.Where (cmb => string.IsNullOrEmpty(cmb) == false)
As an aside, this methodology could have user array which is smaller in size than the title array as a plus.
The Aggregate function is overlooked, here it is in action:
int index = 0;
user.Aggregate (new List(),
(result, usr) =>
{
if (string.IsNullOrEmpty(usr) == false)
result.Add(string.Format("{0}:{1}", title[index], usr));
++index;
return result;
} )