How to use a class from one C# project with another C# project

后端 未结 9 986
花落未央
花落未央 2020-11-27 15:12

In the same solution, I have two projects: P1 and P2. How can I make use of a class of P1 in P2?

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 15:52

    1. In the 'Solution Explorer' tree, expand the P2 project and then right-click the project and select 'Add Reference' from the menu.
    2. On the 'Add Reference' dialog, select the 'Projects' tab and select your P1 project.
    3. If you are using namespaces then you will need to import the namespaces for your P1 types by adding 'using' statements to your files in P2.

    Note that the types in P1 that you wish to access directly must have a sufficient access level: typically this means they must be made public.

提交回复
热议问题