开发者

how do i call another .cs program from a c# console application? [closed]

开发者_运维百科 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

forgive me but i'm just new. so how do i solve the question above? thanks a lot.


You can't execute a .cs file, as that needs to be compiled first.

When you compiled that file, you got an .exe file. Using Process.Start you can execute that.

There ARE ways to compile-and-execute sourcecode from within a C# program, but that is an advanced subject and probably not what you need.

If this is not what you want, please edit your question and provide more details.


If you just want to use some methods and classes, just add it into the project, and bring the namespace into scope. And it should be OK. (I'm using visual studio)


If you want to use the class contained in the .cs file you need to Add it as an existing file into your project

click on the project in the solution explorer ... right click -> add -> add existing

if the file is part of another project you could then maybe in the add file dialogue add it as a link (probably not recommended).

If the .cs is part of another project and you want to use the class as it is compiled in that p.roject you have 2 options

1) add a reference to the project and make sure the class is public.

2) add the project as an existing project to your solution and then add a reference to the project from inside your solution

with all these methods the class in the .cs is probably in a different namespace meaning you will also have to put a using statement at the top of your file.

eg

using System.Collections.generic

you almost definatley do not want to compile the code during execution of your console app and then execute that ... you would have no idea what the code will do. Its a huge security risk.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜