我试图使用List<T>
与我的自定义类,并且能够使用像列表上的Contains()
,Find()
等方法。我想我只需要使用操作符重载==
但显然,这样做的一个方法是使用一个委托方法与Find()
...C# - 使用列表<T>。查找()与自定义对象
注:现在,我已经超载Equals()
方法获取Contains()
方法工作,但我仍然无法使Find()
函数工作。
让两者都能工作的最佳方式是什么?
我使用最新的C#/.NET框架版本与mono,在Linux上。
编辑:这里是我的代码
using System;
namespace GuerreDesClans
{
public class Reponse : IEquatable<Reponse>
{
public Reponse()
{
m_statement = string.Empty;
m_pointage = 0;
}
public Reponse (string statement, int pointage)
{
m_pointage = pointage;
m_statement = statement;
}
/*
* attributs privés
*/
private string m_statement;
private int m_pointage;
/*
* properties
*/
public string Statement {
get { return m_statement; }
set { m_statement = value; }
}
public int Pointage {
get { return m_pointage; }
set { m_pointage = value; }
}
/*
* Equatable
*/
public bool Equals (Reponse other)
{
if (this.m_statement == other.m_statement)
return true;
else
return false;
}
}
}
,我想如何使用find()函数来搜索我的效应初探对象...
list.find("statement1"); // would return a Reponse object
你是如何调用'Find'? – SLaks 2010-12-21 01:59:24
显示一些代码。 – 2010-12-21 02:00:50