这些是c#中的method的要求Set():ConstructsanemptysetEmpty:Returnstrueifthesetcontainsnoelement,elsefalse(read-only)Count:Returnsthenumberofelementsintheset(read-only)this...
这些是c#中的method的要求
Set() :Constructs an empty set
Empty :Returns true if the set contains no element, else false (read-only)
Count :Returns the number of elements in the set (read-only)
this[int index]:Returns the object at index (read-only), be sure and screen the index value that comes in to ensure it's within the range of your set
Contains(object o):Returns a bool, true if the Set contains the object, else false
Add(object o):Adds the object o to the Set if it is not contained already. Returns a bool, true if o was added, else false
Remove(object o):Removes the object o from the Set if it is present. Returns a bool, true if removed, else false
Equals(object o):Returns true if and only if two Set objects store the same values. (note: we are working with a set, therefore, order is unimportant).
GetHashCode():Returns an int value that is a representation of the Set. Two Set classes that are equal (method Equals() returns true) must also have equal GetHashCode() values.
ToString():Returns a string representation of the Set class. In the following format: [ value1, value2, value3, ] (a comma-separated list enclosed in square-brackets -- newlines between entries is ok).
以下是模板,需添加。在添加一个test, 使c#运行。
using System;
using System.Collections;
using System.Linq;
using System.Text;
/*
Name: Mengyi Gong
Class Description:
*/
namespace Assignment1
{
public class Set
{
ArrayList list = new ArrayList();
public Set()
{
// code... :)
}
public int Count
{
get
{
// ...
}
}
public bool Empty
{
get
{
// ...
}
}
public object this[int index]
{
get
{
// ...
}
}
public bool Contains(object o)
{
return list.Contains(o);
}
public bool Add(object o)
{
if (Contains(o) == true)
{
list.Add(o);
return true;
}
else
return false;
}
public bool Remove(object o)
{
list.Remove(o);
if (list.Count == 0)
return true;
else
return false;
}
public override bool Equals(object o)
{
// ...
}
public override int GetHashCode()
{
// ...
}
public override string ToString()
{
string temp = null;
return temp;
}
}
}
额。。那就是用c#的arraylist,对c#不熟悉 才学一周 这个实在是不会了 还请各位高手帮帮我吧
展开