LINQ String manipulation

shers

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

I have an IEnumerable as a result of LINQ, which contains Value and Count. After I get the result, I want to do a string manipulation on the Value and make the corresponding Count to half. Is that possible with LINQ?

Thanks
 
I have managed to get two IEnumerables with LINQ. They are like this.

A contains
Value: x Count: 4
Value: y Count: 2
Value: z Count: 5

B contains
Value: n Count: 3
Value: y Count: 1

I wish to join these values to get one List, so that the values look like this

Value: x Count: 4
Value: y Count: 3
Value: z Count: 5
Value: n Count: 3

How can I get this to work? Please help.

Thanks
 
Somebody please help me!!

This query would work if some experts give me a helping hand.

Dim q = From b in Item2 Join a in Item1 on b.Value Equals a.Value Select New With {b.Value, .Count = b.Count + a.Count}

This gives me a list of only that's common in both Item1 and Item2. I want the other items that were there in Item1 to still remain, add those in Item2 that are not there in Item1, and those common between Item1 and Item2 to have the Count value added.
Please help.

I cannot find another option :(

Thanks
 
Dim AB = From item In A.Concat(B)
         Group By key = item.value Into g = Group
         Select New With {.value = key, 
                          .count = g.Sum(Function(gItem) gItem.count)}

or .count by Aggregate clause:
                          .count = Aggregate gItem In g Into Sum(gItem.count)
 
Back
Top