Append Loop Variable to Variable Name

前端 未结 3 1533
夕颜
夕颜 2021-01-26 05:04

I have 5 DataTables that needs to be converted to TXT files. Instead of creating them separately, I thought I use a for loop. Here\'s my code:

Strin         


        
3条回答
  •  再見小時候
    2021-01-26 06:00

    There are not enough information in the question to know exactly what the problem is, so I'm just guessing here. Your problem is that you have five objects, that all have a method, and these method have different names. The methods return the same thing, though, DataTable, that can be used in a loop.

    If that's the case then just take out of the loop that which is different, so that in the loop remains that which is identical. Something like this:

    DataTable[] fiveTables =
    {
        file1BLO.SelectFile1ForCSV(),
        file2BLO.SelectFile2ForCSV(),
        file3BLO.SelectFile3ForCSV(),
        file4BLO.SelectFile4ForCSV(),
        file5BLO.SelectFile5ForCSV()
    }
    
    for (int i = 1; i <= 5; i++)
    {
        // Use fiveTables[i] for DataTable, and i for file name
    }
    

提交回复
热议问题