Adding distinct value to each CSV file given my code

gal mor 141 Reputation points
2022-12-15T10:46:27.967+00:00

Hello.
I have the following code which seperates my Records.CSV files to two different CSV files based on COMPID (-> a key given in a dictionary I created):
(the first 3 files): records -> sepereated into two above :

270969-filecreated.png

anyways, I need to count each compId individually(basically each file) for the number of rows and add it distinctly like the following:
270975-csvcreated.png

and this is my function:
270998-code.png

now my problem is, that I cant distinct each file to get its own length, as showed in red ( in the code ), the top line will be the same in each CSV.
how can I achieve two different lengths for two different files, given the solution I already have?
thanks!

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
322 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,240 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 26,506 Reputation points Microsoft Vendor
    2022-12-16T08:39:10.01+00:00

    Hi @gal mor ,
    Since the data is read row by row, you can set two variables to count the number of rows of data added to each file.

                string compId1 = "aa";  
                string compId2 = "bb";  
                Dictionary<string, int> dic = new Dictionary<string, int>();  
                dic.Add(compId1, 0);  
                dic.Add(compId2, 0);  
      
                dic[compId]++;//After readLine every time.  
    

    Best Regards.
    Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments