Namespaces in C# vs imports in Java and Python

后端 未结 6 1491
一整个雨季
一整个雨季 2021-02-20 03:21

In the Java and Python world, you look at a source file and know where all the imports come from (i.e. you know in which file the imported classes are defined). For example:

6条回答
  •  孤独总比滥情好
    2021-02-20 04:00

    1) You're right. There is no "direct" way to know where your class comes from at first glance, but, as you said, you can jump to it in the IDE. But declaring the class this way is just the shortest way to do it. If you wanted, and assuming your Bar class comes from the Foo one, you could declare it

    private foo.Bar myBar = new foo.Bar();
    

    This way it would help knowing where your classes come from at first look.

    2)When you add a reference to your class, the Add reference windows gives you the informations you are looking for. And if you want to know where they come from after you declared it, there is a window named "Solution Explorer" where you can find these informations, under the "References" tree node. You can set it to be always visible (which it is by default)

提交回复
热议问题