开发者

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

开发者 https://www.devze.com 2022-12-30 06:00 出处:网络
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 s

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 enou开发者_Python百科gh 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);
     }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消