public class C2
{
public static void Main()
{
C2 myC2=new C2();
ArrayList myArrayList=new ArrayList();
Console.WriteLine("myArrayList的初始容量={0}",myArrayList.Count);
Console.WriteLine("add方法添加对象并指定其ID分别0-14");
for(int i=0;i<15;i++)
{
  myArrayList.Add(new ObjectElement(i) ); }
myC2.WriteList(myArrayList);
Console.WriteLine("insert分别在索引8,16 insert对象并指定其ID为17 ,20 ");
myArrayList.Insert(8,new ObjectElement(17));
myArrayList.Insert(16,new ObjectElement(20));
myC2.WriteList(myArrayList); Console.WriteLine("sort of myArrayList:");
myArrayList.Sort();
myC2.WriteList(myArrayList); Console.WriteLine("myArrayList copy myArrayList1:");
ArrayList myArrayList1=new ArrayList();
myArrayList.Clone();
myC2.WriteList(myArrayList1); Console.ReadLine();
}
public void WriteList(ArrayList myArrayList)
{
int Capacity=0;
    int pSize=myArrayList.Count;
Console.WriteLine("output myArrayList of Element:");
for(int i=0;i<pSize;i++)
{
    ObjectElement myOE=(ObjectElement)myArrayList[i];//从数组中取出指定的元素
Console.WriteLine(myOE.getID+","); }
Console.WriteLine("Capacity={0},pSize={1}",myArrayList.Capacity,pSize); }
}
public class ObjectElement:IComparable
{
    private int ObjectID;
public  ObjectElement(int pID)
{
 this.ObjectID=pID; }
public void getID
{
get
{
 return ObjectID;
}
}
public int CompareTo(Object pObject)
{
     ObejctElement myObjectElement=(ObjectElement)pObject;
return this.ObjectID.CompareTo(myObjectElement.ObjectID);
}
}
}
c:\inetpub\wwwroot\c\C2.cs(56): 命名空间“c”已经包含了“ObjectElement”的定义
public class ObjectElement:IComparable??
yaqi

解决方案 »

  1.   

    提示已经比较清晰了,就是同一个命名空间里其他文件中已经有
    public class ObjectElement
    在一个命名空间里不能有重名的2个类,C#2.0倒是有“分部类”这一说~~~
      

  2.   

    //你用的是默认的命名空间,肯定已经有同名的类ObjectElement了
    //下面还有错误,请参看注释using System;
    using System.Collections;public class C2
    {
    public static void Main()
    {
    C2 myC2=new C2();
    ArrayList myArrayList=new ArrayList();
    Console.WriteLine("myArrayList的初始容量={0}",myArrayList.Count);
    Console.WriteLine("add方法添加对象并指定其ID分别0-14");
    for(int i=0;i<15;i++)
    {
    myArrayList.Add(new ObjectElement(i) ); }
    myC2.WriteList(myArrayList);
    Console.WriteLine("insert分别在索引8,16 insert对象并指定其ID为17 ,20 ");
    myArrayList.Insert(8,new ObjectElement(17));
    myArrayList.Insert(16,new ObjectElement(20));
    myC2.WriteList(myArrayList); Console.WriteLine("sort of myArrayList:");
    myArrayList.Sort();
    myC2.WriteList(myArrayList); Console.WriteLine("myArrayList copy myArrayList1:");
    ArrayList myArrayList1=new ArrayList();
    myArrayList.Clone();
    myC2.WriteList(myArrayList1); Console.ReadLine();
    }
    public void WriteList(ArrayList myArrayList)
    {
    int Capacity=0;
    int pSize=myArrayList.Count;
    Console.WriteLine("output myArrayList of Element:");
    for(int i=0;i<pSize;i++)
    {
    ObjectElement myOE=(ObjectElement)myArrayList[i];//从数组中取出指定的元素
    Console.WriteLine(myOE.getID+","); }
    Console.WriteLine("Capacity={0},pSize={1}",myArrayList.Capacity,pSize); }
    }
    public class ObjectElement:IComparable
    {
    private int ObjectID;
    public  ObjectElement(int pID)
    {
    this.ObjectID=pID; }
    //把void改为int
    public int getID
    {
    get
    {
    return ObjectID;
    }
    }
    public int CompareTo(Object pObject)
    {
    //Object拼写错
    ObjectElement myObjectElement=(ObjectElement)pObject;
    return this.ObjectID.CompareTo(myObjectElement.ObjectID);
    }
    }
      

  3.   

    善意提醒楼上的楼上的一下,C#已经在讨论4.0了,传说是回归人类语言,麻烦的sigh一把
    相信vs已经支持C#3.0了,你的意思应该是framework 2.0吧ps:我又无聊了