LINQ Average

shers

Well-known member
Joined
Aug 12, 2007
Messages
86
Programming Experience
1-3
Hi,

I have a List (Of String()). I wish to find the count of the 3 item in each string array in the list. Is there an easy way to find it using linq?

Thanks
 
Average implies a mathematical operation, ie numeric values, but you say the items are strings. Then you talk about counting items. What do you mean?
 
You could do a ForEach and add up the count:
Dim count As Integer
list.ForEach(Sub(x) count += x.Length)

or Sum:
Dim count = list.Sum(Function(x) x.Length)

I think you should update your forum profile, VS 2005/.Net 2.0 didn't have Linq.
 
From what I can gather, you're trying to get a list of the characters appearing at index 2 in the Strings and a count of the number of times they each appear. Is that correct? If so then there is definitely no average involved. If you want to do it with LINQ then it would require grouping. Otherwise, you could just use a loop.

Also, please do as JohnH says and update your profile if you are actually using .NET 3.5 or later.
 
Back
Top