I'm going to assume the key issue here is getting the TextBoxes that have text content passed to the 'mainlib.AddtoList method which I assume has an input parameter like this:
mainlib.AddtoList(params string[] args)
Assuming you have an Array of the TextBoxes used for input named 'TbxAry:
private TextBoxEx[] TbxAry;
TbxAry = new TextBoxEx[]
{
textBox1, textBox2, textBox3, textBox4
};
private void SomeButton_Click(object sender, EventArgs e)
{
mainlib.AddtoList(TbxAry
.Where(tbx => (!string.IsNullOrEmpty(tbx.Text)))
.Select(tbx => tbx.Text).ToArray()
);
}
I would eliminate a separate TextBox to hold a 'Count, and handle that some other way. You might consider using a Dictionary like this:
Dictionary<int, List<List<string>>> NToStrings;
which would be updated before you call mainlib.AddToList...
That way, you'd never have use Linq and pull out the Lists that have the same number of items. You'd just do this:
List<List<string>> results;
if(NToStrings.TryParse(3, out results))
{
{
else
{
}