读书人

函数参数的有关问题

发布时间: 2012-04-01 17:23:46 作者: rapoo

函数参数的问题
看别人的代码,有如下的函数定义,不明白是什么意思,请教各位。

1.
Public Shared Function AttachI(Of typAS As {Class, New})(ByVal objAttach As typAS) As typAS


2.
Public Shared Function GetI(Of typAS As {Class, New})() As typAS




[解决办法]
1.
Public Shared Function AttachI(Of typAS As {Class, New})(ByVal objAttach As typAS) As typAS
函数AttachI有一个参数 类型是typAS,并且返回typAS,typAS 必须是一个类,有缺省构造函数


2.
Public Shared Function GetI(Of typAS As {Class, New})() As typAS
函数AttachI没有参数,返回typAS, typAS 必须是一个类,有缺省构造函数

{Class, New}这个叫类型参数的约束-- Constraints on Type Parameters。

参考
http://msdn.microsoft.com/en-us/library/d5x73970(v=vs.80).aspx
虽然是C#,但是是msdn的权威解释。

读书人网 >VB Dotnet

热点推荐