关于C#的类的问题和函数重载

我是菜鸟,然后编了一个关于输入整数排序输出跟输入字符串倒序输出的代码出错了,不知道怎么改,求救!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 排序sort
{
class Program
{
static void Main(string[] args)
{
int[] arr = { 3, 1, 2, 8 };
sort(arr);
string[] str = { hello };

sort(str);

}

class sort
{
public void sort(int[] array)
{
int t;
for (int i = array.Length; i > 0; i--)
{
for (int j = 0; j < i; j++)
{
if (array[j] > array[j + 1])
{
t = array[j];
array[j] = array[j + 1];
array[j + 1] = t;
}
}
}
for (int k = 0; k < array.Length; k++)
{
Console.Write("{0},", array[k]);
}
}
public void sort(string[] s)
{
for (int i = s.Length; i > 0; i--)
{
Console.Write("{0}", s[i]);
}

}
}
}
}

第1个回答  2012-03-19
1. Main方法中调用了sort方法,但sort方法没有定义过,你只在sort类中定义了sort方法
你有两个选择:
(1)实例化sort类,用对象调用sort方法
(2)把sort方法放到Program类中成为静态方法,调用
2. string数组的唯一元素hello没有定义过,如果你想要hello字符串,应当加上双引号
3. 类sort中有一个方法也叫sort,这是不允许的,只有构造函数可以和类同名
相似回答
大家正在搜