C#中 如何调用自定义函数
namespace 方法和函数{
class Program
{
static void Main(string[] args)
{
int d = getcount();
}
public void print()
{
Console.WriteLine("输出数据");
}
public int getcount()
{
return 300;
}
public int add(int a,int b)
{
return a + b;
}
public string add(string str1, string str2)
{
return str1 + str2;
}
}
}
自定义函数是写在什么地方,而且如何调用?刚刚学,见谅。
谢谢 --------------------编程问答-------------------- 多看看 基础的书把 现在别人给你现成代码 告诉你 一点好处也没 你也不懂 --------------------编程问答-------------------- static void Main是程序的入口
你的处理函数写在自己定义的功能类中
然后再Main中实例化你自己的类
完成所需要的处理
--------------------编程问答--------------------
class Program
{
private YourClass classObj;
static void Main(string[] args)
{
classObj = new YourClass();
int d = classObj.getcount();
}
}
public class YourClass
{
public void print()
{
Console.WriteLine("输出数据");
}
public int getcount()
{
return 300;
}
public int add(int a,int b)
{
return a + b;
}
public string add(string str1, string str2)
{
return str1 + str2;
}
}
read book .
补充:.NET技术 , C#