Mono和Array.Sort

时间:2016-02-25 00:58:30

标签: c# linux mono monodevelop

如何使用Monodevelop在Mono中使用Array.Sort(someArray)!我使用的是Mono 4.2.2和Monodevelop 5.10。

我是否必须导入一些命名空间?哪一个?

还有其他方法可供使用吗?

我一直在努力尝试并且不起作用:

var Color = new String[5];

Color[0] = "Orange";
Color[1] = "Blue";
Color[2] = "Purple";
Color[3] = "Green";
Color[4] = "Red";

Array.Sort(Color); //Error: The type or namespace name 'Sort' does not exist in namespace 'Array'. Are you missing an assembly reference?

Console.WriteLine ("Colors:");

foreach(string s in Color)
{
    Console.WriteLine (s);
}

1 个答案:

答案 0 :(得分:0)

Array位于System命名空间中,包含在mscorlib内(Mono / .Net 2/4 / 4.5 +)。

使用:

using System;

剪切/粘贴示例:

using System;

namespace ArraySort
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var Color = new String[5];

            Color[0] = "Orange";
            Color[1] = "Blue";
            Color[2] = "Purple";
            Color[3] = "Green";
            Color[4] = "Red";

            Array.Sort(Color); //Error: The type or namespace name 'Sort' does not exist in namespace 'Array'. Are you missing an assembly reference?

            Console.WriteLine ("Colors:");

            foreach(string s in Color)
            {
                Console.WriteLine (s);
            }
        }
    }
}

输出:

Colors:
Blue
Green
Orange
Purple
Red

Press any key to continue...