将你的 myfun 定义中加一个 static 就行了:using System;
public class a
{
public static int myfun(string str)
{
int bk;
bk=Convert.ToInt32(str);
bk*=2;
return bk;
}
public static void Main()
{
int i;
string s="123";
i=myfun(s);
Console.WriteLine(i);
}}