从控制台应用程序调用函数 [英] Calling a Function from console Application

查看:287
本文介绍了从控制台应用程序调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有2个控制台应用程序,并声明了一个方法,现在我想在其他控制台应用程序中调用该方法.对此我该怎么办.

Hi,

I have 2 console application and have declared a method and now I wan to call that method in other console application .What should I do for That.

推荐答案

您好,Mohd,

您可以添加对dll或exe的引用.因此,如果该方法(应为公共方法)是.NET可执行文件的一部分,请将该可执行文件添加为对您的项目的引用.现在,您可以在代码中添加合适的使用"声明,然后调用它.

修改

下面的代码假定在名称空间"my.name.sapce"中有一个名为Program的类,该类具有两个方法,其中一个是静态方法,另一个是实例方法.
最终修改

Hi Mohd,

you can add a reference to a dll or to an exe. So if the method (should be public) is part of an .NET executable, add that executable as a reference to your project. You can now add a suitable "using" declaration to your code and call it.

Modification

Code below assumes that in name space "my.name.sapce" there''s class called Program that has two methods one of which is static and the other an instance method.
End Modification

using my.name.space;
...
public void Test()
{
    Program.AStaticMethod();
    Program p = new Program();
    p.ANonStaticMethod();
}
...




干杯


Manfred




Cheers


Manfred



这篇关于从控制台应用程序调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆