我有5組lists
,我需要比較。要求是使用通用方法來做到這一點。通用方法來比較兩個列表
例如,我有列表Teacher
和Student
。 Teacher
具有TeacherId
作爲其標識符,而Student
具有StudentId
。是否有可能創造條件,採取的方法:
var result = Compare (teacherA, teacherB, "TeacherId");
var result = Compare (studentA, studentB, "StudentId");
它可能類似於此頂端回答一句:How can I create a generic method to compare two list of any type. The type may be a List of class as well
但這是否意味着我要創建每個每個list
5點型IComparable
的方法呢?對不起,我對C#很陌生。
絕對推薦使用的框架結構爲這裏提出的接口。 –