1

私はクラスを持っています:

public class Author : Entity
{
    public virtual string ForeName { get; set; }
    public virtual string LastName { get; set; }

    public Author() { }
}

および次を含む別のクラス X:

public virtual IList<Author> Authors { get; set; }

X に既に Author が含まれているかどうかを判断するには、Author の Equals メソッドをオーバーライドするのが最善の方法ですか?

4

1 に答える 1

1

著者のリストをお持ちの場合、私にとって最良の検索方法は辞書です。

var auditors = list.ToDictionary<IdType, Author>(key => key.Id, value => value)
Auditor auditor;
if(auditors.ContainsKey(key))
{
   auditor = auditors[key];
}

また

Auditor auditor;
if(auditors.TryGetValue(key, out auditor))
{
   ...
}
于 2012-05-01T12:08:48.083 に答える