How to access namespace which is part of different project?

前端 未结 2 1881
时光说笑
时光说笑 2021-01-20 12:26

I have two C#.net projects project 1 and project 2 (names changed) in single solution. I am using Visual Studio 2005. I have added reference of project 2 in project 1 by rig

2条回答
  •  离开以前
    2021-01-20 12:38

    Make sure the classes you want to access are public. So suppose you have the following class in Project 2:

    namespace Project2
    {
        public class Foo { }
    }
    

    In Project 1 after you've referenced Project 2 you can use this class:

    namespace Project1
    {
        using Project2;
    
        public class Bar
        {
            public Bar()
            {
                Foo foo = new Foo();
            }
        }
    }
    

提交回复
热议问题