-2

Can you use namespaces in one program to get the classes from those other programs in your program? Or do you do this using assemblies? And how do you do it?

  • 1
    *"get the classes from those other programs in your program"* - what do you call "programms"? DLLs? You have to reference dlls (add it to references of the project) and then you can use public stuff from that dll. – Sinatr Apr 13 '18 at 10:11
  • Simply google what a namespace and what an assembly is. This is far too broad for a single answer here. – MakePeaceGreatAgain Apr 13 '18 at 10:12

2 Answers2

0

If you are trying to use code from one c# project in other you just need to add a reference in the project you are going to consume the code to the project with the code to be consumed.

If you are trying to consume code from an already compiled assembly and this compiled assembly is .net you can either use reflection or .net decompiler to get the code.

Jetbrains have a .net decompiler.

  • reflection to get code? Reflection will only make the types and members accessable, but won´t expose their internal implementation. – MakePeaceGreatAgain Apr 13 '18 at 10:13
  • Right. Reflection allows to access the classes and use them but certainly won't get you the code. But the original question was about using classes, wasn't it? – Daniel Blanquez Moya Apr 13 '18 at 10:16
0

To use classes defined in another program (let us call this program an "assembly"), you can reference that assembly in your program/application and use the classes. The classes have to be defined as public in that other assembly.

An assembly is basically an .exe or a .dll, as explained in this answer. Usually classes that are meant to be reused are defined in a class library and compiled to a .dll.

The goal of namespaces is to separate the code into meaningful pieces, as explained here. A namespace creates a sort of "full name" for a class. So, in you program you will have to reference a class defined in another program/assembly by its full name, meaning using its namespace and its class name.

Developer
  • 435
  • 4
  • 16