什么是集会? [英] What is an assembly?

查看:161
本文介绍了什么是集会?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚朋友是什么关键字呢。我知道它

指定元素可以在同一个程序集中访问,

但这没有用,因为我不知道什么是程序集是。我知道

项目是什么,我知道解决方案是什么,但是汇编是指在任何地方的帮助文件中都没有定义
。任何人都可以提供一个简单的

定义吗?

I''m trying to figure out what the "Friend" keyword does. I know it
specifies that "elements are accessible from within the same assembly",
but that doesn''t help because I don''t know what an assembly is. I know
what a project is, and I know what a solution is, but "assembly" isn''t
defined in the help file anywhere. Can anyone provide a simple
definition?

推荐答案



" TC" < go ********* @ yahoo.comwrote in message

news:11 ********************* @ p79g2000cwp.googlegro ups.com ...



:我正在试图找出朋友的内容。关键字呢。我知道它

:指定元素可以在同一个程序集中访问,

:但这没有用,因为我不知道是什么集会是。我知道

:项目是什么,我知道解决方案是什么,但是汇编是什么?不是
:在任何地方的帮助文件中定义。任何人都可以提供一个简单的

:定义吗?

这是非常简单的(并且不完整),但希望它会给你

你开始点。

将程序集视为包含一个或多个类或

结构的代码块。这样的程序集可以是库(DLL)的一部分,也可以是

独立可执行文件(EXE)的一部分。通常情况下,类和结构将彼此逻辑相关,但它们并不是绝对必须的。

所以,让我们说你决定建立一个简单的小hello world可执行的

包含一个类:

文件:HelloWorld.vb

============== ==================================== ==========

Public Class HelloWorld

Public Shared Sub Main(Args()As String)

System.Console.Writeline(" Hello World!")

结束次级

结束班级

======================== ========================== ==========

您可以将此文件编译成并且可以通过从命令提示符运行以下

命令来执行(确保VBC编译器在路径中:)

C:\> vbc helloworld.vb

这将生成文件helloworld.exe。然后你可以从

命令行运行它。此可执行文件是程序集。尽管如此,还是允许使用小型和trival。但是

让我们通过创建两个新文件来改变它:

文件1: HelloWorld1.vb

======================================= =========== ==========

公共类HelloWorld1

Public Shared Sub Main(Args()As String )

Dim Hw2作为新的HelloWorld2

Hw2.Say(Hello World Too!)

End Sub

结束班

===================================== ============= ==========

文件2:HelloWorld2.vb

===== ============================================= ===== =====

Public Class HelloWorld2

Public Sub Say(Something As String)

Dim Hw3 As New HelloWorld3

Hw3.Repeat(Something)

结束次级

结束班级


朋友级HelloWorld3

Public Sub Repeat(Something As String)

System.Console.WriteLine(Something)

End Sub

结束班

==================================== ============== ==========

如果您编译这两个文件,您将获得两个程序集。一块蛋糕。

现在这里是棘手的部分...

File1中的Sub Main()可以访问类HelloWorld2(File2)中的Sub Say() />
,因为该类是Public。

然而,File1中的Sub Main()无法访问类HelloWorld3中的子Repeat()
(File2),因为class是朋友类。类HelloWorld1和

HelloWorld3是两个独立的程序集,因此类HelloWorld3不能从类HelloWorld1调用


另一方面,类HelloWorld2和HelloWorld3在同一个

程序集中,因此它们可以相互访问。因此,在
类HelloWorld2中的子Say()可以访问类HelloWorld3中的子Repeat()。

我确定这和泥一样清楚,但是我说这有希望让你

开始。

拉尔夫

-

-

----------------------------------------------- -----------

* ^〜^ ^〜^ *

* _ {~~} {~~} _ *

* / _``> *< > *<'''_ _ \\ * *

*(\ --_)++)(++(_ - /)*

-------------------------------------------------- --------

合气道没有高级学生 - 只有

有能力的初学者。没有先进的技术 -

只有正确应用基本原则。


"TC" <go*********@yahoo.comwrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
:
: I''m trying to figure out what the "Friend" keyword does. I know it
: specifies that "elements are accessible from within the same assembly",
: but that doesn''t help because I don''t know what an assembly is. I know
: what a project is, and I know what a solution is, but "assembly" isn''t
: defined in the help file anywhere. Can anyone provide a simple
: definition?
This is extremely simplistic (and incomplete), but hopefully it will give
you a starting off point.
Think of an assembly as a block of code that contains one or more classes or
structures. Such assemblies can be part of a library (DLL) or part of a
stand alone executable (EXE). Typically, the classes and structures will be
logically related to one another, but they don''t absoulely have to be.
So let''s say you decide to build a simple little "hello world" executable
that contains a single class:
File: HelloWorld.vb
================================================== ==========
Public Class HelloWorld
Public Shared Sub Main(Args() As String)
System.Console.Writeline("Hello World!")
End Sub
End Class
================================================== ==========
You can compile this file into and executable by running the following
command from a command prompt (be sure the VBC complier is in the path:)
C:\>vbc helloworld.vb
This will generate the file "helloworld.exe" which you can then run from the
command line. This executable is an assembly. Small and trival granted, but
an assembly nonetheless.
Let''s change this somewhat by creating two new files:
File 1: HelloWorld1.vb
================================================== ==========
Public Class HelloWorld1
Public Shared Sub Main(Args() As String)
Dim Hw2 As New HelloWorld2
Hw2.Say("Hello World Too!")
End Sub
End Class
================================================== ==========
File 2: HelloWorld2.vb
================================================== ==========
Public Class HelloWorld2
Public Sub Say(Something As String)
Dim Hw3 As New HelloWorld3
Hw3.Repeat(Something)
End Sub
End Class

Friend Class HelloWorld3
Public Sub Repeat(Something As String)
System.Console.WriteLine(Something)
End Sub
End Class
================================================== ==========
If you compile these two files, you will get two assemblies. Piece of cake.
Now here is the tricky part...
Sub Main() in File1 can access the sub Say() in class HelloWorld2 (File2)
because that class is Public.
However, Sub Main() in File1 cannot access sub Repeat() in class HelloWorld3
(File2) because that class is a Friend Class. Classes HelloWorld1 and
HelloWorld3 are two separate assemblies, so class HelloWorld3 cannot be
called from class HelloWorld1.
On the otherhand, classes HelloWorld2 and HelloWorld3 are in the same
assembly, so they are accessible to one another. Therefore, sub Say() in
class HelloWorld2 can access sub Repeat() in class HelloWorld3.
I''m sure this is as clear as mud, but as I said this will hopefully get you
started.
Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.


谢谢你的解释。在你的例子中,这两个类定义了

。在同一个.vb文件中的b属于同一个程序集,但是在其他.vb文件中定义的类是b $ b属于不同的程序集。是

定义的一个汇编,然后?每个汇编包含在单个.vb文件中定义的所有代码



_AnonCoward写道:
Thank you for the explanation. In your example, the two classes defined
in the same .vb file belong to the same assembly, but the class defined
in other .vb file belongs to a different assembly. Is that the
definition of an assembly, then? Each assembly contains all the code
defined within a single .vb file?
_AnonCoward wrote:

" TC"< go ********* @ yahoo.comwrote in message

news:11 ************** *******@p79g2000cwp.googlegro ups.com ...



:我想弄清楚朋友是什么关键字呢。我知道它

:指定元素可以在同一个程序集中访问,

:但这没有用,因为我不知道是什么集会是。我知道

:项目是什么,我知道解决方案是什么,但是汇编是什么?不是
:在任何地方的帮助文件中定义。任何人都可以提供一个简单的

:定义吗?


这是非常简单的(并且不完整),但希望它能给出

你是一个起点。


将程序集想象成包含一个或多个类或

结构的代码块。这样的程序集可以是库(DLL)的一部分,也可以是

独立可执行文件(EXE)的一部分。通常情况下,类和结构将在逻辑上相互关联,但它们并不是绝对必须的。


所以让's'说你决定建立一个简单的小hello world。可执行的

包含一个类:


文件:HelloWorld.vb

========== ======================================== ==========

Public Class HelloWorld

Public Shared Sub Main(Args()As String)

System.Console.Writeline(" Hello World!" ;)

结束次级

结束班级

==================== ============================== ==========


您可以通过从命令提示符运行以下

命令将此文件编译成可执行文件(确保VBC编译器在路径中:)


C:\> vbc helloworld.vb


这将生成文件helloworld.exe然后你可以从

命令行运行它。此可执行文件是程序集。尽管如此,还是允许使用小型和trival,但是

尽管如此。


让我们通过创建两个新文件来改变它:


文件1:HelloWorld1.vb

=============================== =================== ==========

公共类HelloWorld1

公共共享Sub Main(Args()As String)

Dim Hw2 As New HelloWorld2

Hw2.Say(Hello World Too!)

结束分

结束课

============================= ===================== ==========


文件2:HelloWorld2.vb

=========================================== ======= ==========

Public Class HelloWorld2

Public Sub Say(Something As String)

Dim Hw3 As New HelloWorld3

Hw3.Repeat(Something)

End Sub

End Class


朋友级HelloWorld3

公共子重复(字符串)

System.Console .WriteLine(Something)

End Sub

End Class

================= ================================= ==========


如果编译这两个文件,您将获得两个程序集。一块蛋糕。


现在这里是棘手的部分...


File1中的Sub Main()可以访问sub Say()在类HelloWorld2(File2)中

,因为该类是Public。


然而,File1中的Sub Main()无法访问类HelloWorld3中的子Repeat() br />
(File2)因为该类是一个朋友类。类HelloWorld1和

HelloWorld3是两个独立的程序集,因此类HelloWorld3不能从类HelloWorld1调用



另一方面,类HelloWorld2和HelloWorld3在同一个

程序集中,因此它们可以相互访问。因此,在
类HelloWorld2中的子Say()可以访问类HelloWorld3中的子Repeat()。


我确定这就像泥浆一样清晰,但正如我所说,这将有希望得到你

开始。


拉尔夫

-

-

--------------------------------------- -------------------

* ^〜^ ^〜^ *

* _ {~~} { ~~} _ *

* / _``> *< > *<'''_ _ \\ * *

*(\ --_)++)(++(_ - /)*

-------------------------------------------------- --------

合气道没有高级学生 - 只有

有能力的初学者。没有先进的技术 -

只有正确应用基本原则。
"TC" <go*********@yahoo.comwrote in message
news:11*********************@p79g2000cwp.googlegro ups.com...
:
: I''m trying to figure out what the "Friend" keyword does. I know it
: specifies that "elements are accessible from within the same assembly",
: but that doesn''t help because I don''t know what an assembly is. I know
: what a project is, and I know what a solution is, but "assembly" isn''t
: defined in the help file anywhere. Can anyone provide a simple
: definition?
This is extremely simplistic (and incomplete), but hopefully it will give
you a starting off point.
Think of an assembly as a block of code that contains one or more classes or
structures. Such assemblies can be part of a library (DLL) or part of a
stand alone executable (EXE). Typically, the classes and structures will be
logically related to one another, but they don''t absoulely have to be.
So let''s say you decide to build a simple little "hello world" executable
that contains a single class:
File: HelloWorld.vb
================================================== ==========
Public Class HelloWorld
Public Shared Sub Main(Args() As String)
System.Console.Writeline("Hello World!")
End Sub
End Class
================================================== ==========
You can compile this file into and executable by running the following
command from a command prompt (be sure the VBC complier is in the path:)
C:\>vbc helloworld.vb
This will generate the file "helloworld.exe" which you can then run from the
command line. This executable is an assembly. Small and trival granted, but
an assembly nonetheless.
Let''s change this somewhat by creating two new files:
File 1: HelloWorld1.vb
================================================== ==========
Public Class HelloWorld1
Public Shared Sub Main(Args() As String)
Dim Hw2 As New HelloWorld2
Hw2.Say("Hello World Too!")
End Sub
End Class
================================================== ==========
File 2: HelloWorld2.vb
================================================== ==========
Public Class HelloWorld2
Public Sub Say(Something As String)
Dim Hw3 As New HelloWorld3
Hw3.Repeat(Something)
End Sub
End Class

Friend Class HelloWorld3
Public Sub Repeat(Something As String)
System.Console.WriteLine(Something)
End Sub
End Class
================================================== ==========
If you compile these two files, you will get two assemblies. Piece of cake.
Now here is the tricky part...
Sub Main() in File1 can access the sub Say() in class HelloWorld2 (File2)
because that class is Public.
However, Sub Main() in File1 cannot access sub Repeat() in class HelloWorld3
(File2) because that class is a Friend Class. Classes HelloWorld1 and
HelloWorld3 are two separate assemblies, so class HelloWorld3 cannot be
called from class HelloWorld1.
On the otherhand, classes HelloWorld2 and HelloWorld3 are in the same
assembly, so they are accessible to one another. Therefore, sub Say() in
class HelloWorld2 can access sub Repeat() in class HelloWorld3.
I''m sure this is as clear as mud, but as I said this will hopefully get you
started.
Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.


TC,


程序集是一个构建程序,无论如何它是。


Cor


" TC"< go ********* @ yahoo.comschreef in bericht

新闻:11 ********************** @ 75g2000cwc.googlegro ups.com ...
TC,

An assembly is a build program whatever it is.

Cor

"TC" <go*********@yahoo.comschreef in bericht
news:11**********************@75g2000cwc.googlegro ups.com...

感谢您的解释。在您的示例中,在同一个.vb文件中定义的两个类属于同一个程序集,但是类定义了
其他.vb文件中的
属于不同的程序集。那是一个程序集的

定义吗?Ea ch assembly包含在单个.vb文件中定义的所有代码


$ b _AnonCoward写道:
Thank you for the explanation. In your example, the two classes defined
in the same .vb file belong to the same assembly, but the class defined
in other .vb file belongs to a different assembly. Is that the
definition of an assembly, then? Each assembly contains all the code
defined within a single .vb file?
_AnonCoward wrote:

>" TC" < go ********* @ yahoo.comwrote in message
新闻:11 ********************* @ p79g2000cwp.googlegr oups.com ......

:我想弄清楚朋友是什么关键字呢。我知道
:指定元素可以在同一个程序集中访问,
:但这没有用,因为我不知道程序集是什么。我知道
:项目是什么,我知道解决方案是什么,但是组装是什么?不是
:在任何地方的帮助文件中定义。任何人都可以提供一个简单的定义吗?

这是非常简单的(并且不完整),但希望它会给你一个起点。

将程序集视为包含一个或多个类

结构的代码块。此类程序集可以是库(DLL)的一部分,也可以是独立可执行文件(EXE)的一部分。通常情况下,这些课程和结构在逻辑上彼此相关,但他们并不是绝对必须的。

所以,让我们说你决定建立一个简单的小hello world可执行文件
包含单个类:

文件:HelloWorld.vb
====================== =========================== ===========
公共课HelloWorld
公开Shared Sub Main(Args()As String)
System.Console.Writeline(" Hello World!")
End Sub
End Class
====== =========================================== ======= ====

您可以通过从命令提示符运行以下
命令将此文件编译成可执行文件(确保VBC编译器位于路径中)

C:\> vbc helloworld.vb

这将生成文件helloworld.exe。然后你可以从
命令行运行。此可执行文件是程序集。尽管如此,仍然允许使用小型和繁琐的工具。

让我们通过创建两个新文件来改变它:

文件1: HelloWorld1.vb
=========================================== ====== ===========
Public Class HelloWorld1
Public Shared Sub Main(Args()As String)
Dim Hw2 As New HelloWorld2
Hw2.Say(Hello World Too!)
End Sub
End Class
=================== ============================== ===========

档案2:HelloWorld2.vb
========================================= ======== ===========
Public Class HelloWorld2
Public Sub Say(Something as String)
Dim Hw3 As New HelloWorld3 Hw3.Repeat(Something)
End Sub
End Class

朋友类HelloWorld3
Public Sub Repeat(Something As String)
System.Console。 WriteLine(Something)
End Sub
End Class
============================== =================== ===========

如果编译这两个文件,您将获得两个程序集。一块
蛋糕。

现在这里是棘手的部分...

File1中的Sub Main()可以访问类HelloWorld2中的Sub Say() File2)
因为该类是公共的。

然而,File1中的Sub Main()无法访问类中的子Repeat()HelloWorld3
(File2),因为class是朋友类。类HelloWorld1和
HelloWorld3是两个独立的程序集,因此无法从类HelloWorld1调用类HelloWorld3。

另一方面,类HelloWorld2和HelloWorld3在同一个
组装,因此彼此可以访问。因此,HelloWorld2类中的子Say()可以访问HelloWorld3类中的子Repeat()。

我确定这个就像泥浆一样清晰,但正如我所说的那样希望如此得到
你已经开始了。

拉尔夫
-
-
------------- ---------------------------------------------
* ^〜^ ^〜^ *
* _ {~~} {~~} _ *
* / _``> *< > *<'''_ _ \\ * *
*(\ - _)++)(++(_-- /)*
-------- --------------------------------------------------
合气道没有高级学生 - 只有
有能力的初学者。没有先进的技术 - 只有正确应用基本原则。
>"TC" <go*********@yahoo.comwrote in message
news:11*********************@p79g2000cwp.googlegr oups.com...
:
: I''m trying to figure out what the "Friend" keyword does. I know it
: specifies that "elements are accessible from within the same assembly",
: but that doesn''t help because I don''t know what an assembly is. I know
: what a project is, and I know what a solution is, but "assembly" isn''t
: defined in the help file anywhere. Can anyone provide a simple
: definition?
This is extremely simplistic (and incomplete), but hopefully it will give
you a starting off point.
Think of an assembly as a block of code that contains one or more classes
or
structures. Such assemblies can be part of a library (DLL) or part of a
stand alone executable (EXE). Typically, the classes and structures will
be
logically related to one another, but they don''t absoulely have to be.
So let''s say you decide to build a simple little "hello world" executable
that contains a single class:
File: HelloWorld.vb
================================================= ===========
Public Class HelloWorld
Public Shared Sub Main(Args() As String)
System.Console.Writeline("Hello World!")
End Sub
End Class
================================================= ===========
You can compile this file into and executable by running the following
command from a command prompt (be sure the VBC complier is in the path:)
C:\>vbc helloworld.vb
This will generate the file "helloworld.exe" which you can then run from
the
command line. This executable is an assembly. Small and trival granted,
but
an assembly nonetheless.
Let''s change this somewhat by creating two new files:
File 1: HelloWorld1.vb
================================================= ===========
Public Class HelloWorld1
Public Shared Sub Main(Args() As String)
Dim Hw2 As New HelloWorld2
Hw2.Say("Hello World Too!")
End Sub
End Class
================================================= ===========
File 2: HelloWorld2.vb
================================================= ===========
Public Class HelloWorld2
Public Sub Say(Something As String)
Dim Hw3 As New HelloWorld3
Hw3.Repeat(Something)
End Sub
End Class

Friend Class HelloWorld3
Public Sub Repeat(Something As String)
System.Console.WriteLine(Something)
End Sub
End Class
================================================= ===========
If you compile these two files, you will get two assemblies. Piece of
cake.
Now here is the tricky part...
Sub Main() in File1 can access the sub Say() in class HelloWorld2 (File2)
because that class is Public.
However, Sub Main() in File1 cannot access sub Repeat() in class
HelloWorld3
(File2) because that class is a Friend Class. Classes HelloWorld1 and
HelloWorld3 are two separate assemblies, so class HelloWorld3 cannot be
called from class HelloWorld1.
On the otherhand, classes HelloWorld2 and HelloWorld3 are in the same
assembly, so they are accessible to one another. Therefore, sub Say() in
class HelloWorld2 can access sub Repeat() in class HelloWorld3.
I''m sure this is as clear as mud, but as I said this will hopefully get
you
started.
Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.



这篇关于什么是集会?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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