命名空间 - 广泛的问题 [英] Namespaces - broad question

查看:43
本文介绍了命名空间 - 广泛的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对名称空间的正确使用和有用性感到困惑。我相信我

了解目的是这样,开发人员可以在命名空间中放置类

来基本上组织你的代码。我理解你声明你的

意图通过继承来在页面中使用命名空间。属性。

我知道使用继承并不是绝对必要的,它只是建议使用
所以开发人员不必在代码中输入整个命名空间

。我知道名称空间必须出现在项目程序集中,然而...... b $ b ...


程序集如何找到开发人员编写的命名空间? ??

在我见过的所有例子中,名称空间都是用代码隐藏的

页面编写的。这如何使整个项目可以访问它们?什么是

防止重复的命名空间被写入不同的代码隐藏

页面?是否有更好的地方可以编写所有项目命名空间以获得更多

集中可访问性?


最后,命名空间如何从类中删除?


随机

I''m confused about the proper use and usefulness of namespaces. I beleive I
understand the purpose is so the developer can put classes within namespaces
to essentially organize your code. And I understand that you declare your
intention to use a namespace within a page through the "Inherits" attribute.
I know that using "Inherits" isn''t absolutely necessary, it''s just
recommended so the developer doesn''t have to type out the entire namespace
in code. I know that namespaces have to appear in the project assembly,
however...

How does the assembly find a namespace that the developer has written????
In all the examples I''ve seen, namespaces have been written in codebehind
pages. How does this make them accessible to the entire project? What''s to
prevent a duplicate namespace from being written in a different codebehind
page? Is there a better place to write all the project namespaces for more
centralized accessibility?

And finally, how do namespaces DIFFER from classes?

Random

推荐答案

首先,命名空间可以与''Imports''关键字一起使用,所以不能

必须为每个类写出完整的命名空间,而不是''Inherits''

属性。


想想名称空间作为文件系统中的文件夹,类作为文件

。因此,命名空间本身不仅仅是一个组织

容器的类 - 就像文件夹只是文件的容器一样。

类是实际的东西你实例化,并调用方法。


我真的不明白你的问题。我认为它们都源于不了解命名空间实际上是什么。


随机 < CI ******* @ hotmail.com>在消息中写道

新闻:uD ************** @ TK2MSFTNGP10.phx.gbl ...
First of all, namespaces can be used with the ''Imports'' keyword, so as not
have to write out the full namespace for every class, not the ''Inherits''
attribute.

Think of namespaces as folders in your file system, and classes as the files
in them. So a namespace itself isn''t anything but an organizational
container for classes - just as a folder is just a container for files.
Classes are the actual things that you instantiate, and call methods on.

I didn''t really understand your questions. I think they all stem from not
understanding what a namespace actually is.

"Random" <ci*******@hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP10.phx.gbl...
我很困惑关于名称空间的正确使用和有用性。我相信
我理解其目的是让开发人员可以将类放在
名称空间中来实际组织你的代码。我理解您声明通过继承在页面中使用命名空间的意图。
属性。我知道使用继承并不是绝对必要的,它只是建议所以开发人员不必在代码中输入整个命名空间。我知道命名空间必须出现在项目程序集中,然而......

程序集如何找到开发人员编写的命名空间????
我见过的例子,名称空间已经写在代码隐藏的页面中。这如何使整个项目可以访问它们?什么是
来防止在不同的代码隐藏页面中写入重复的命名空间?是否有更好的地方为
更集中的可访问性编写所有项目命名空间?

最后,如何从类中命名空间DIFFER?

随机
I''m confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I understand that you declare your
intention to use a namespace within a page through the "Inherits" attribute. I know that using "Inherits" isn''t absolutely necessary, it''s just
recommended so the developer doesn''t have to type out the entire namespace
in code. I know that namespaces have to appear in the project assembly,
however...

How does the assembly find a namespace that the developer has written????
In all the examples I''ve seen, namespaces have been written in codebehind
pages. How does this make them accessible to the entire project? What''s to prevent a duplicate namespace from being written in a different codebehind
page? Is there a better place to write all the project namespaces for more centralized accessibility?

And finally, how do namespaces DIFFER from classes?

Random



首先,命名空间可以与''Imports''关键字一起使用,以免

必须写出每个类的完整命名空间,而不是''Inherits''

属性。


将命名空间视为文件系统中的文件夹和类作为文件

在其中。因此,命名空间本身不仅仅是一个组织

容器的类 - 就像文件夹只是文件的容器一样。

类是实际的东西你实例化,并调用方法。


我真的不明白你的问题。我认为它们都源于不了解命名空间实际上是什么。


随机 < CI ******* @ hotmail.com>在消息中写道

新闻:uD ************** @ TK2MSFTNGP10.phx.gbl ...
First of all, namespaces can be used with the ''Imports'' keyword, so as not
have to write out the full namespace for every class, not the ''Inherits''
attribute.

Think of namespaces as folders in your file system, and classes as the files
in them. So a namespace itself isn''t anything but an organizational
container for classes - just as a folder is just a container for files.
Classes are the actual things that you instantiate, and call methods on.

I didn''t really understand your questions. I think they all stem from not
understanding what a namespace actually is.

"Random" <ci*******@hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP10.phx.gbl...
我很困惑关于名称空间的正确使用和有用性。我相信
我理解其目的是让开发人员可以将类放在
名称空间中来实际组织你的代码。我理解您声明通过继承在页面中使用命名空间的意图。
属性。我知道使用继承并不是绝对必要的,它只是建议所以开发人员不必在代码中输入整个命名空间。我知道命名空间必须出现在项目程序集中,然而......

程序集如何找到开发人员编写的命名空间????
我见过的例子,名称空间已经写在代码隐藏的页面中。这如何使整个项目可以访问它们?什么是
来防止在不同的代码隐藏页面中写入重复的命名空间?是否有更好的地方为
更集中的可访问性编写所有项目命名空间?

最后,如何从类中命名空间DIFFER?

随机
I''m confused about the proper use and usefulness of namespaces. I beleive I understand the purpose is so the developer can put classes within namespaces to essentially organize your code. And I understand that you declare your
intention to use a namespace within a page through the "Inherits" attribute. I know that using "Inherits" isn''t absolutely necessary, it''s just
recommended so the developer doesn''t have to type out the entire namespace
in code. I know that namespaces have to appear in the project assembly,
however...

How does the assembly find a namespace that the developer has written????
In all the examples I''ve seen, namespaces have been written in codebehind
pages. How does this make them accessible to the entire project? What''s to prevent a duplicate namespace from being written in a different codebehind
page? Is there a better place to write all the project namespaces for more centralized accessibility?

And finally, how do namespaces DIFFER from classes?

Random



嗯。我正在尝试从示例,教程和书籍中自学。

特别是在这种情况下,我正在尝试从MS PortalStarterKit学习。

具体来说,该示例中的默认页面为第一行

default.aspx:


<%@ Page CodeBehind =" Default.aspx.vb" ;语言= QUOT; VB" AutoEventWireup =" false"

Inherits =" ASPNET.StarterKit.Portal.CDefault" %>


代码隐藏页面包含:


命名空间ASPNET.StarterKit.Portal

公共类CDefault

继承System.Web.UI.Page

Private Sub Page_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)Handles MyBase.Load

< code here>

End Sub

End Class

End Namespace


我试图找出它的工作方式和原因。这比教程和书籍给出的例子更复杂。


再次,我想弄清楚命名空间是如何声明的这里是

它进入大会的方式。并且因为它确实在某种程度上使整个项目可以获得



随机


"匡" <所以***** @ nospam.com>在留言中写道

news:%2 **************** @ TK2MSFTNGP09.phx.gbl ...
Hmm. I''m trying to teach myself from examples and tutorials and books.
Specifically in this case, I''m trying to learn from the MS PortalStarterKit.
Specifically, the default page in that example has as the first line in
default.aspx:

<%@ Page CodeBehind="Default.aspx.vb" language="vb" AutoEventWireup="false"
Inherits="ASPNET.StarterKit.Portal.CDefault" %>

The codebehind page has:

Namespace ASPNET.StarterKit.Portal
Public Class CDefault
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
<code here>
End Sub
End Class
End Namespace

I''m trying to find out how and why this works the way that it does. It''s
more complex than the examples given by tutorials and books.

And again, I''m trying to figure out how the namespace declared here makes
it''s way into the assembly. And because it does, somehow, does that make it
available through the entire project?

Random

"Marina" <so*****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
First of所有,命名空间都可以与''Imports''关键字一起使用,因此不必为每个类写出完整的命名空间,而不是''Inherits''
属性。

将名称空间视为文件系统中的文件夹,将类视为
文件。因此,命名空间本身不仅仅是类的组织容器 - 就像文件夹只是文件的容器一样。
类是您实例化的实际内容,并且调用方法。 br />
我真的不明白你的问题。我认为它们都源于不了解名称空间实际上是什么。

随机 < CI ******* @ hotmail.com>在消息中写道
新闻:uD ************** @ TK2MSFTNGP10.phx.gbl ...
First of all, namespaces can be used with the ''Imports'' keyword, so as not
have to write out the full namespace for every class, not the ''Inherits''
attribute.

Think of namespaces as folders in your file system, and classes as the files in them. So a namespace itself isn''t anything but an organizational
container for classes - just as a folder is just a container for files.
Classes are the actual things that you instantiate, and call methods on.

I didn''t really understand your questions. I think they all stem from not
understanding what a namespace actually is.

"Random" <ci*******@hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP10.phx.gbl...
我对正确使用感到困惑名称空间的有用性。 I
beleive
I''m confused about the proper use and usefulness of namespaces. I beleive
了解目的是这样,开发人员可以将命名空间放在命名空间
understand the purpose is so the developer can put classes within namespaces
中,从根本上组织你的代码。我知道您声明
to essentially organize your code. And I understand that you declare



您打算通过Inherits


your intention to use a namespace within a page through the "Inherits"


属性在页面中使用命名空间。


attribute.

我知道使用继承并不是绝对必要的,它只是建议所以开发人员不必在代码中输入整个
命名空间。我知道命名空间必须出现在项目程序集中,然而......

程序集如何找到开发人员有
写的命名空间????在我看过的所有示例中,命名空间都是用
代码隐藏页面编写的。这如何使整个项目可以访问它们?
I know that using "Inherits" isn''t absolutely necessary, it''s just
recommended so the developer doesn''t have to type out the entire namespace in code. I know that namespaces have to appear in the project assembly,
however...

How does the assembly find a namespace that the developer has written???? In all the examples I''ve seen, namespaces have been written in codebehind pages. How does this make them accessible to the entire project? What''s to
阻止在不同的



代码隐藏页面中写入重复的命名空间?是否有更好的地方为


codebehind page? Is there a better place to write all the project namespaces for

编写所有项目命名空间
更多


more

集中可访问性?

最后,如何从类中命名空间DIFFER?

随机
centralized accessibility?

And finally, how do namespaces DIFFER from classes?

Random




这篇关于命名空间 - 广泛的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆