How to have nested query with LINQ

This line:

var csvLinesData = csvlines.Skip(1).Select(l => l.Split(',').ToArray());

produces an IEnumerble<string[]>. When you select it, you can access the columns of your CSV, as you do in this line:

CSRName = data[12],

The problem with this line:

csvLinesData.Count(w => w.direction='I')

is that an element of csvLinesData is a string[] which doesn’t have a direction field or property.

Anyhow, it looks strange that you count all the lines with a specific property, because it would result in the same number for every “user”.

Because I don’t know what you actually want to do (I can’t even guess), I cannot tell you what to do.


Edit, based on new section in the question:

You cannot assign an integer to a string:

Incomming = csvLinesData.Count(w => w[4] == "I"),

Either change the property Incomming to an integer or create a string from the number (Which is probably not what you need):

Incomming = csvLinesData.Count(w => w[4] == "I").ToString(),

By the way, it still cannot work, because you count all the lines where column 5 == "I", which leads to the same number for each user. Your example has a different number in each line (but the same user name). This is very confusing. You really have to think about what you actually want to do and either explain it clearly or provide some example data.

Leave a Comment