简体   繁体   中英

how can I validate column names and count in an List array? C#

I'm trying to get this resolved in .NET 2.0 and unfortunately that is not negotiable.

I am reading in a csv file with columns of data that 'should' correspond to a List of tickers in IdentA with some modifications. The csv file columsn would read:

A_MSFT,A_CSCO,_A_YHOO,B_MSFT,B_CSCO,B_YHOO,C_MSFT,C_CSCO,C_YHOO

IdentA[0]="MSFT"<br>
IdentA[1]="CSCO"<br>
IdentA[2]="YHOO"<br>

The AssetsA array is populated with the csv data<br>
AssetsA[0]=0<br>
AssetsA[1]=1.1<br>
AssetsA[2]=0<br>
AssetsA[3]=2<br>
AssetsA[4]=3.2<br>
AssetsA[5]=12<br>
AssetsA[6]=54<br>
AssetsA[7]=13<br>
AssetsA[8]=0.2<br>

The C_ columns are optional but if they exist they all need to exist. All of the suffixes must match the values in IdentA. The values in the csv files all need to be decimal. I'm using a group of 3 as an example, there could be any number of tickers in the IdentA array.

Its easy enough to do the first part:

    for (int x = 0; x < IdentA.Count; x++)
    {
        decimal.TryParse(AssetsA[x + IdentA.Count], out currentelections);
    }

So that will get me the first set of values for the A_ columns but how can I get through B_ and C_ ? I can't do something as simple as IdentA.Count*2...

EDIT: IdentA gets populated when the first line of the csv is read, AssetsA is populated on subsequent lines until EOF. The original designer just always assumed that B_ and C_ would always exist and the data would just 'fall into place'. Going to look at what it would take to redesign it :(

use 2d arrays to go through two arrays like so

for(int i = 0; i <= twoDeeArr[0].Count-1; i++)
{
     for(int j = 0; j <= twoDeeArr.Count-1; j++)
     {
          decimal.TryParse((decimal)twoDeeArr[i][j], out currentElections);
     }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM