/// <summary> /// A result is a search result which contains a post and its ranking. /// </summary> internal class Result : IComparable<Result> { #region Constants and Fields /// <summary> /// The post of the result. /// </summary> internal IPublishable Item; /// <summary> /// The rank of the post based on the search term. The higher the rank, the higher the post is in the result set. /// </summary> internal int Rank; #endregion #region Public Methods /// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public override int GetHashCode() { return this.Item.Id.GetHashCode(); } #endregion #region Implemented Interfaces #region IComparable<Result> /// <summary> /// Compares the current object with another object of the same type. /// </summary> /// <param name="other"> /// An object to compare with this object. /// </param> /// <returns> /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value /// has the following meanings: Value Meaning Less than zero This object is less than the other parameter.Zero /// This object is equal to other. Greater than zero This object is greater than other. /// </returns> public int CompareTo(Result other) { return other.Rank.CompareTo(this.Rank); } #endregion #endregion } 看看
if (dic.ContainsKey(_bsMod))//如果集合中包含此对象,直接返回Table如果我要像这样写,该怎么实现。。
可参考
http://blog.csdn.net/aladdinty/article/details/3400837
但如果是不同的对象,但值一样与必须重写 Equals
/// A result is a search result which contains a post and its ranking.
/// </summary>
internal class Result : IComparable<Result>
{
#region Constants and Fields /// <summary>
/// The post of the result.
/// </summary>
internal IPublishable Item; /// <summary>
/// The rank of the post based on the search term. The higher the rank, the higher the post is in the result set.
/// </summary>
internal int Rank; #endregion #region Public Methods /// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode()
{
return this.Item.Id.GetHashCode();
} #endregion #region Implemented Interfaces #region IComparable<Result> /// <summary>
/// Compares the current object with another object of the same type.
/// </summary>
/// <param name="other">
/// An object to compare with this object.
/// </param>
/// <returns>
/// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value
/// has the following meanings: Value Meaning Less than zero This object is less than the other parameter.Zero
/// This object is equal to other. Greater than zero This object is greater than other.
/// </returns>
public int CompareTo(Result other)
{
return other.Rank.CompareTo(this.Rank);
} #endregion #endregion
}
看看
if (dic.ContainsKey(_bsMod))//如果集合中包含此对象,直接返回Table如果我要像这样写,该怎么实现。。