-1

In the sample data below I need to find how many TransitMapSegmentIDs match TransitLine's 10803 TransitMapSegmentIDs, which would be 2 since 101 and 102 match.

I've been looking at this for a few hours and I'm a little cross eyed and would appreciate some help. Thanks!

public class TransitLineSegment
{
    public int TransitLineID { get; set; }
    public string TransitLineName { get; set; }
    public int TransitMapSegmentID { get; set; }
    public string HexColor { get; set; }
    public double[][] Coordinates { get; set; }
    public int Width { get; set; }
}

sample data

TransitMapSegmentID  TransitLineID
101                  10803
102                  10803
64                   10807
67                   10807
101                          10807
102                          10807
4

2 に答える 2

2

WhereフィルタとGroupBy:を組み合わせることができます

var result = transitLineSegments
            .Where(ls => ls.TransitLineID == 10803)
            .GroupBy(ls => ls.TransitMapSegmentID)
            .Select(grp => grp.Count());    
于 2012-05-31T22:27:16.887 に答える
1

GroupByメソッドを使用します。TransitLineID でグループ化して、各 ID のリストを取得できるはずです。最初の ID を取得したり、数えたりできます。

var uni = from segment in segments
      group segment by segment.TransitLineID into segmentGroup
      select new { Id = segmentGroup.Key, Count = segmentGroup.Count() };

foreach(var seg in uni)
    Console.WriteLine ("Id: {0}, Count: {1}", seg.Id, seg.Count);
于 2012-05-31T22:19:58.397 に答える