How to access namespace which is part of different project?

前端 未结 2 1882
时光说笑
时光说笑 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();
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-20 12:57

    Import is a Visual Basic.NET term. In C# you would use using.

    0 讨论(0)
提交回复
热议问题