转自:http://www.cnblogs.com/el-net/articles/1045825.html

Removes the first occurrence of a specific object from the IList.

方案一
This method determines equality using the default comparer Comparer<(Of<(T>)>).Default. Comparer<(Of <(T>)>).Default checks whether type Timplements System.IComparable<(Of <(T>)>) and uses that implementation, if available. If not, Comparer<(Of <(T>)>).Default checks whether type T implementsSystem.IComparable. If type T does not implement either interface, this method uses Object.Equals.

This method is an O(n) operation, where n is Count.

其实备注中已经给我指明了解决方案."this method uses Object.Equals"

所以我们重写Object.Equals方法即可.
 

  class DemoList
    
{
        
private string _s;
        
public DemoList() { }
        
public DemoList(string _s)
        
{
            
this._s = _s;
        }

        
public string s
        
{
            
get return _s; }
            
set { _s = value; }
        }

        
public override bool Equals(object obj)
        
{     
            
if (this.s == ((DemoList)obj).s)
            
{
                
return true;
            }

            
else
            
{
                
return false;
            }
         
        }

    }
posted on 2011-06-07 17:31  tonylx  阅读(180)  评论(0)    收藏  举报