[英]Why there are 2 () in a sub signature?
Recently I asked a question and got a working answer. 最近我问了一个问题并得到了有效的答案。 The code below is the working code. 下面的代码是工作代码。 I have problem understand the Sub signature. 我在理解Sub签名时遇到问题。 Why there are two ()() for the sub. 为什么子有两个()()。 I mean I don't understand the first one (Of Algorithm As SymmetricAlgorithm)
. 我的意思是我不理解第一个(Of Algorithm As SymmetricAlgorithm)
。 Obviously the second one is for the paramater. 显然,第二个参数是针对参数的。 Can you point to me where I can read more about it? 您能指出我在哪里可以了解更多信息吗?
Public Shared Sub DecryptTo(Of Algorithm As SymmetricAlgorithm)(sourceStream As Stream, stream As Stream, password As String)
Dim pdb = GetPassword(password)
Using alg = Activator.CreateInstance(Of Algorithm)()
Using trans = alg.CreateDecryptor(pdb.GetBytes(alg.KeySize / 8), pdb.GetBytes(16))
Using cStream = New CryptoStream(sourceStream, trans, CryptoStreamMode.Read)
cStream.CopyTo(stream)
End Using
End Using
End Using
End Sub
At http://msdn.microsoft.com/en-us/library/w256ka79(v=vs.80).aspx one can find a description of Generics (which is the reason for the first set of parentheses). 在http://msdn.microsoft.com/zh-cn/library/w256ka79(v=vs.80).aspx上,可以找到对泛型的描述(这是第一组括号的原因)。
It starts: 开始:
A generic type is a single programming element that adapts to perform the same functionality for a variety of data types. 通用类型是单个编程元素,适用于对各种数据类型执行相同的功能。 When you define a generic class or procedure, you do not have to define a separate version for each data type for which you might want to perform that functionality. 定义通用类或过程时,不必为可能要执行该功能的每种数据类型定义单独的版本。
An analogy is a screwdriver set with removable heads. 一个类比是带有可移动头的螺丝刀。 You inspect the screw you need to turn and select the correct head for that screw (slotted, crossed, starred). 您检查需要转动的螺钉,并为该螺钉选择正确的头部(开槽,划线,加星号)。 Once you insert the correct head in the screwdriver handle, you perform the exact same function with the screwdriver, namely turning the screw. 将正确的头插入螺丝起子手柄后,即可使用螺丝起子执行完全相同的功能,即旋转螺丝。
Screwdriver set as a generic tool 螺丝刀设置为通用工具
When you define a generic type, you parameterize it with one or more data types. 定义通用类型时,可以使用一种或多种数据类型对其进行参数化。 This allows the using code to tailor the data types to its requirements. 这允许使用代码根据其要求定制数据类型。 Your code can declare several different programming elements from the generic element, each one acting on a different set of data types. 您的代码可以从通用元素声明几个不同的编程元素,每个元素都作用于一组不同的数据类型。 But the declared elements all perform the identical logic, no matter what data types they are using. 但是,无论它们使用的是哪种数据类型,声明的元素都执行相同的逻辑。
For example, you might want to create and use a queue class that operates on a specific data type such as String. 例如,您可能想创建和使用对特定数据类型(例如String)进行操作的队列类。 You can declare such a class from System.Collections.Generic.Queue, as the following example shows. 您可以从System.Collections.Generic.Queue声明这样的类,如以下示例所示。
VB Public stringQ As New System.Collections.Generic.Queue(Of String) VB公共stringQ作为新的System.Collections.Generic.Queue(字符串)
You can now use stringQ to work exclusively with String values. 现在,您可以使用stringQ专门处理String值。 Because stringQ is specific for String instead of being generalized for Object values, you do not have late binding or type conversion. 因为stringQ是特定于String的,而不是泛化为Object值的,所以您没有后期绑定或类型转换。 This saves execution time and reduces run-time errors. 这样可以节省执行时间并减少运行时错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.