各位大虾好,我来请教个问题,希望能有人来帮帮我,给我点“烛光”,帮我照明前方,嘿嘿
这是我照书上写的代码,定义了一个冒泡排序法的类,
using System;
using System.Collections ;
using System.Text;
namespace Chapter35
{
    enum SortType
    {
        ASC,
        DESC
    }
    class BubbleSort
    {
        private SortType order;\\这是定义字段
        private int[] list;
        public SortType order\\定义属性
        {
            get { return order; }
            set { order = value; }
        }
        public int[] list
        {
            get { return list; }
            set { list = value; }
}
        public BubbleSort()\\构造函数
        { order = SortType.ASC; }
        public BubbleSort(int[] arr)
        {
            order = SortType.ASC;
            list = arr;
        }
        public BubbleSort(int[] arr, SortType type)
        {
            list = arr;
            order = type;
        }
        private void Swap(ref int a, ref int b)\\私有方法
        {
            int c = a;
            a = b;
            b = c;
        }
        public void Sort()\\公有方法
        {
            bool isOK = false;
            while (!isOK)
            {
                isOK = true;
                for (int i = 0; i < list.Length - 1; i++)
                {
                    switch (order)
                    {
                        case SortType.ASC:
                            {
                                if (list[i] > list[i + 1])
                                    Swap(ref  list[i], ref list[i + 1]);
                                isOK = false;
                                break;
                            }
                        case SortType.DESC:
                            {
                                if (list[i] > list[i + 1])
                                    Swap(ref  list[i], ref list[i + 1]);
                                isOK = false;
                                break;
                            }
                    }
                }
            }
        }
        static void Main(string[] args)
        {
            int[] list1 ={ 1, 0, 6, 5, 7, 9, 2, 8, 3, 4 };
            BubbleSort sort = new BubbleSort(list1 );
            Console.WriteLine("排序后");
            sort.Sort();
            for (int i = 0; i < list1.Length; i++)
                Console.WriteLine(list1[i]);
}
    }
}
我在运行这个程序的时候出现错误,如下
错误 1 类型“Chapter35.BubbleSort”已经包含“order”的定义 Program.cs 22 25 enum1
错误 2 类型“Chapter35.BubbleSort”已经包含“list”的定义 Program.cs 27 22 enum1
各位帮我看看这是怎么回事吧,真的谢谢各位大虾了!
private SortType order;\\这是定义字段
public SortType order\\定义属性、
属性和字段不能同名呀,见意:字段_order,属性:Order...
楼上正解