C# 在一个解决方案中调用来自不同项目的方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11092708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 16:26:58  来源:igfitidea点击:

Calling methods from different Projects in one Solution

c#linqvisual-studio-2010

提问by user1316502

There are 3 Projects in 1 Solution. Main manipulations I make from the main file in the 1st Project. However I need to call methods and use classes from the 3rd Project. For example:

1 个解决方案中有 3 个项目。我从第一个项目的主文件中进行的主要操作。但是我需要调用方法并使用第三个项目中的类。例如:

– 3rd Project has:

– 第三个项目有:

public DataClasses1DataContext() :     base(global::WindowsFormsApplication1.Properties.Settings.Default.mediaBorshchConnectionString, mappingSource)
 { OnCreated(); } 

What is the right way to call it from my 1st Project?

从我的第一个项目中调用它的正确方法是什么?

DataClasses1DataContext borshch = new DataClasses1DataContext()

采纳答案by Jacob

You need to add a reference to the 3rd project in your 1st project. To do this, right-click on your project, select "Add Reference," then select the project in your solution. Once your main project references the 3rd project, then you can access its public types.

您需要在第一个项目中添加对第三个项目的引用。为此,请右键单击您的项目,选择“添加引用”,然后在您的解决方案中选择该项目。一旦您的主项目引用了第三个项目,您就可以访问它的公共类型。