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

后端 未结 9 975
花落未央
花落未央 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:33

    If you have two projects in one solution folder.Just add the Reference of the Project into another.using the Namespace you can get the classes. While Creating the object for that the requried class. Call the Method which you want.

    FirstProject:

    class FirstClass()
    {
       public string Name()
       {
          return "James";
       }
    }
    

    Here add reference to the Second Project

    SecondProject:

    class SeccondClass
    {
        FirstProject.FirstClass obj=new FirstProject.FirstClass();
        obj.Name();
    }
    

提交回复
热议问题