.Net 类库里没有集合类的吗?

自己写了个,大家提提意见~~

.Net 集合类using System;
.Net 集合类
using System.Collections;
.Net 集合类
.Net 集合类
namespace CN.Teddy.Util.Collections
{

.Net 集合类    
/// ISimpleSet 的摘要说明。
.Net 集合类    
/// </summary>
.Net 集合类    public interface ISimpleSet : ICollection, ICloneable
{
.Net 集合类        
bool Contains(object obj);
.Net 集合类
.Net 集合类        
bool BelongTo(SimpleSet set2);
.Net 集合类
.Net 集合类        
void Add(object obj);
.Net 集合类
.Net 集合类        
void Remove(object obj);
.Net 集合类
.Net 集合类        
void Clear();
.Net 集合类
.Net 集合类        SimpleSet Intersect(SimpleSet set2);
.Net 集合类
.Net 集合类        SimpleSet Union(SimpleSet set2);
.Net 集合类
.Net 集合类        SimpleSet Minus(SimpleSet set2);
.Net 集合类    }

.Net 集合类}

.Net 集合类

.Net 集合类using System;
.Net 集合类
using System.Collections;
.Net 集合类
.Net 集合类
namespace CN.Teddy.Util.Collections
{

.Net 集合类    
/// SimpleSet 的摘要说明。
.Net 集合类    
/// </summary>
.Net 集合类    public class SimpleSet : ISimpleSet
{

.Net 集合类
.Net 集合类        
private ArrayList _Data = null;
.Net 集合类        
private IEqualHandler _EqualHandler = null;
.Net 集合类
.Net 集合类        
private void InitPrivateMembers()
{
.Net 集合类            _Data 
= new ArrayList();
.Net 集合类            
if (_EqualHandler == null)
{
.Net 集合类                _EqualHandler 
= new EqualHandler();
.Net 集合类            }

.Net 集合类        }

.Net 集合类    
.Net 集合类
.Net 集合类        
#endregion
.Net 集合类

.Net 集合类
.Net 集合类        
public object this[int index]
{
.Net 集合类            
get
{
.Net 集合类                
return _Data[index];
.Net 集合类            }

.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
#endregion
.Net 集合类

.Net 集合类
.Net 集合类        
public SimpleSet()
{
.Net 集合类            InitPrivateMembers();
.Net 集合类        }

.Net 集合类
.Net 集合类        
public SimpleSet(IEqualHandler eh)
{
.Net 集合类            _EqualHandler 
= eh;
.Net 集合类            InitPrivateMembers();
.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
#endregion
.Net 集合类

.Net 集合类
.Net 集合类        
public bool IsSynchronized
{
.Net 集合类            
get
{
.Net 集合类                
return _Data.IsSynchronized;
.Net 集合类            }

.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
public int Count
{
.Net 集合类            
get
{
.Net 集合类                
return _Data.Count;
.Net 集合类            }

.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
public void CopyTo(Array array, int index)
{
.Net 集合类            _Data.CopyTo(array, index);
.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
public object SyncRoot
{
.Net 集合类            
get
{
.Net 集合类                
return _Data.SyncRoot;
.Net 集合类            }

.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
#endregion
.Net 集合类

.Net 集合类
.Net 集合类        
public IEnumerator GetEnumerator()
{
.Net 集合类            
return _Data.GetEnumerator();
.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
#endregion
.Net 集合类

.Net 集合类
.Net 集合类        
public bool Contains(object obj)
{
.Net 集合类            
foreach (object item in _Data)
{
.Net 集合类                
if (_EqualHandler.Equal(item, obj))
{
.Net 集合类                    
return true;
.Net 集合类                }

.Net 集合类            }

.Net 集合类            
return false;
.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
public bool BelongTo(CN.Teddy.Util.Collections.SimpleSet set2)
{
.Net 集合类            
bool ret = true;
.Net 集合类            
foreach (object item in _Data)
{
.Net 集合类                
if (!set2.Contains(item))
{
.Net 集合类                    ret 
= false;
.Net 集合类                    
break;
.Net 集合类                }

.Net 集合类            }

.Net 集合类            
return ret;
.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
public void Add(object obj)
{
.Net 集合类            
if (!this.Contains(obj))
{
.Net 集合类                _Data.Add(obj);
.Net 集合类            }

.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
public void Remove(object obj)
{
.Net 集合类            
foreach (object item in _Data)
{
.Net 集合类                
if (_EqualHandler.Equal(obj, item))
{
.Net 集合类                    _Data.Remove(item);
.Net 集合类                    
break;
.Net 集合类                }

.Net 集合类            }

.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
public void Clear()
{
.Net 集合类            _Data.Clear();
.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
public CN.Teddy.Util.Collections.SimpleSet Intersect(CN.Teddy.Util.Collections.SimpleSet set2)
{
.Net 集合类            SimpleSet ret 
= new SimpleSet(_EqualHandler);
.Net 集合类
.Net 集合类            
foreach (object item in _Data)
{
.Net 集合类                
if (set2.Contains(item))
{
.Net 集合类                    ret.Add(item);
.Net 集合类                }

.Net 集合类            }

.Net 集合类
.Net 集合类            
return ret;
.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
public CN.Teddy.Util.Collections.SimpleSet Union(CN.Teddy.Util.Collections.SimpleSet set2)
{
.Net 集合类            SimpleSet ret 
= this.Clone() as SimpleSet;
.Net 集合类
.Net 集合类            
foreach (object item in set2)
{
.Net 集合类                ret.Add(item);
.Net 集合类            }

.Net 集合类
.Net 集合类            
return ret;
.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
public CN.Teddy.Util.Collections.SimpleSet Minus(CN.Teddy.Util.Collections.SimpleSet set2)
{
.Net 集合类            SimpleSet ret 
= this.Clone() as SimpleSet;
.Net 集合类
.Net 集合类            
foreach (object item in set2)
{
.Net 集合类                
if (ret.Contains(item))
{
.Net 集合类                    ret.Remove(item);
.Net 集合类                }

.Net 集合类            }

.Net 集合类
.Net 集合类            
return ret;
.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
#endregion
.Net 集合类

.Net 集合类
.Net 集合类        
public object Clone()
{
.Net 集合类            SimpleSet ret 
= new SimpleSet(_EqualHandler);
.Net 集合类
.Net 集合类            
foreach (object item in _Data)
{
.Net 集合类                ret.Add(item);
.Net 集合类            }

.Net 集合类
.Net 集合类            
return ret;
.Net 集合类        }

.Net 集合类
.Net 集合类
.Net 集合类        
#endregion
.Net 集合类    }

.Net 集合类}

.Net 集合类

.Net 集合类using System;
.Net 集合类
.Net 集合类
namespace CN.Teddy.Util.Collections
{

.Net 集合类    
/// IEqualHandler 的摘要说明。
.Net 集合类    
/// </summary>
.Net 集合类    public interface IEqualHandler
{
.Net 集合类        
bool Equal(object obj1, object obj2);
.Net 集合类    }

.Net 集合类}

.Net 集合类

.Net 集合类using System;
.Net 集合类
.Net 集合类
namespace CN.Teddy.Util.Collections
{

.Net 集合类    
/// EqualHandler 的摘要说明。
.Net 集合类    
/// </summary>
.Net 集合类    public class EqualHandler : IEqualHandler
{

.Net 集合类
.Net 集合类        
public bool Equal(object obj1, object obj2)
{
.Net 集合类            
// TODO:  添加 EqualHandler.Equal 实现
.Net 集合类
            return obj1.Equals(obj2);
.Net 集合类        }

.Net 集合类
.Net 集合类        
#endregion
.Net 集合类    }

.Net 集合类}

.Net 集合类

相关文章:

  • 2021-09-04
  • 2021-08-17
  • 2021-08-01
  • 2022-01-12
  • 2021-12-24
  • 2021-07-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
  • 2022-01-30
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
相关资源
相似解决方案