How can I refer to a project from another one in c#?

前端 未结 9 1148
孤街浪徒
孤街浪徒 2020-12-01 12:13

I added a project, Project2, to my solution. It already had another project lets say Project 1. How can I call classes and methods from project2 into project1?

What

9条回答
  •  执念已碎
    2020-12-01 12:35

    You have to specify the "path" to the code you're trying to call. You accomplish this by either

    1) Specify the namespace of the second project/class you wish to use, typically at the top of your code file.

    using MySecondProject;
    
    var foo = new ClassFromSecondProject();
    

    2) Explicitly specifying the name of the class you wish to use, including its namespace

    //do stuff
    var foo = new MySecondProject.ClassFromSecondProject();
    //do more stuff
    

提交回复
热议问题