简体   繁体   English

为什么子签名中有2()?

[英]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. 这样可以节省执行时间并减少运行时错误。

VB.NET uses parenthesis in several different ways: VB.NET以多种不同方式使用括号:

  • parameter section of method declaration or method calls (same as C#) 方法声明或方法调用的参数部分(与C#相同)
  • declaring generics (equivalent of <> in C#) 声明泛型 (相当于C#中的<>)
  • declaring and indexing arrays (equivalent of [] in C#) 声明和索引数组 (相当于C#中的[])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么签名会...... - &gt;结果 <char*string> ? - Why would the signature be … -> Result<char*string>? 如果更改签名中的返回类型,为什么不调用Web服务? - Why web service not called if I change return type in signature? 为什么在此C#.NET控制器方法中,我具有此签名? - Why in this C# .NET controller method do I have this signature? 为什么此功能与此代理具有不兼容的签名? - Why does this Function have a Non Compatiable Signature with this Delegate? 尽管签名中有返回类型,为什么此方法会继续返回动态? - Why does this method keep returning dynamic despite the return type in the signature? 您更喜欢哪种方法签名?为什么? - Which kind of method signature do you prefer and why? 为什么放在子文件夹中的用户控件中的asp:HyperLink.NagigateUrl包含此子文件夹? - Why asp:HyperLink.NagigateUrl in user control, placed in sub-folder, contains this sub-folder? 为什么这么慢,.net任务嵌套子任务 - why is so slow, .net task nest sub task 递归函数vs Sub与更改参数 - 为什么一个更好 - Recursive Function vs Sub with changing Argument - Why is one better 为什么sub不能同时实现接口和处理事件? - Why can't a sub implement an interface and handle event at the same time?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM