.NET namespaces

前端 未结 9 2388
面向向阳花
面向向阳花 2020-12-31 18:38

My background is primarily as a Java Developer, but lately I have been doing some work in .NET. So I have been trying to do some simple projects at home to get better at wor

9条回答
  •  难免孤独
    2020-12-31 19:19

    Namespaces are a logical grouping, while projects are a physical grouping.

    Why is this important? Think about .NET 2.0, 3.0, and 3.5. .NET 3.0 is basically .NET 2.0 with some extra assemblies, and 3.5 adds a few more assemblies. So for instance, .NET 3.5 adds the DataPager control, which is a web control and should be grouped in System.Web.UI.WebControls. If namespaces and physical locations were identical, it couldn't be because it's in a different assembly.

    So having namespaces as independent logical entities means you can have members of several different assemblies which are all logically grouped together because they're meant to be used in conjunction with each other.

    (Also, there's nothing wrong with having your physical and logical layouts pretty similar.)

提交回复
热议问题