2017-06-14 4 views
-2

私はリストの2つの異なるタイプのオブジェクトを持っており、その特定のオブジェクトにのみOrderByGroupByをしたいです。2つの異なるタイプのリストのオブジェクトをグループ化して並べ替える方法は?

私は両方のリストのためにそれを別々にしたくありません。

今私はこれをやっている:

List<object> combinePlacePerson = (from x in recipientFilteredDataByPersons.OrderBy(x => x.FirstName).GroupBy(x => x.FirstName[0]) select (object)x).ToList(); 
combinePlacePerson.AddRange((from x in recipientFilteredDataByPlaces.OrderBy(x => x.FirstName).GroupBy(x => x.FirstName[0]) select (object)x).ToList()); 
cvrbyperson.Source = combinePlacePerson; 

cvrbypersonCollectionViewSourceオブジェクトです。

しかし、私は結合されたオブジェクトでそれをしたいです。

+0

public interface IHaveFirstName { string FirstName { get; set; } } 

は、このインタフェース

から内部プロパティrecipientFilteredDataByPersonsrecipientFilteredDataByPlacesは今、あなたはこれを行うことができるしている、あなたのクラスを継承recipientFilteredDataByPersonsとrecipientFilteredDataByPlaces?それはどのような種類のリストですか?それらのオブジェクトにはいくつかのプロパティが共通していますか? –

答えて

0

このようなインターフェイスを作成します。作成しているどのように

List<IHaveFirstName> combinePlacePerson = (from x in recipientFilteredDataByPersons 
         select (IHaveFirstName)x).ToList(); //you need inheritance here 
combinePlacePerson.AddRange((from x in recipientFilteredDataByPlaces 
         select (IHaveFirstName)x).ToList()); //and here 
//here you order full collection 
combinePlacePerson = combinePlacePerson.OrderBy(x => x.FirstName) 
             .GroupBy(x => x.FirstName[0]); 
関連する問題