Intersection of lists
问题 Is there a better, more elegant and concise, way to get the intersection of two lists in C#? In C# a method to calculate an intersection of list of dates is: public List<DateTime> dates_common(Timeserie ts1, Timeserie ts2) { var dt1 = new HashSet<DateTime>(ts1.dates); var dt2 = new HashSet<DateTime>(ts2.dates); dt1.IntersectWith(dt2); var dt = new DateTime[dt1.Count]; dt1.CopyTo(dt); return new List<DateTime>(dt); } In Ruby one would do this as: def dates_common(ts1, ts2) dt1 = ts1.dates.to