22

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:

– 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()
double-beep
  • 5,031
  • 17
  • 33
  • 41
user1316502
  • 809
  • 2
  • 10
  • 21

1 Answers1

37

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.

Jacob
  • 77,566
  • 24
  • 149
  • 228
  • Can't believe how difficult some of the other answers made this. Thank you! – Kevin Francis Feb 12 '16 at 20:33
  • 1
    But how would you reference a class deep inside a folder from global.cs for example? Or how to reference code inside another project, but under the same Solution? In my case there is no DLL, EXE, etc – Fandango68 Mar 17 '17 at 05:53
  • @Fernando68: in .NET, you don't reference code; instead, you reference compiled classes, and you can only reference classes that are in your current module or in a module your project has a reference to. It's weird that you don't have DLLs or EXEs without a project (which is what would compile to DLL or EXE). If that's truly the case, you can add a link to the code files within your project. But in most cases, you just need to add a project reference. Or are these files already in the current project and you just need to do a `using Your.Namespace;`? – Jacob Mar 17 '17 at 17:33
  • @Jacob not weird it all. It's called a web site, not a web application. Websites have their ASPX code behind in .CS files. BY default all namespaces in app_code folder are global accessible. But the only way I can do this is if I declare my classes 'static'. I wonder why. – Fandango68 Mar 19 '17 at 23:43