开发者

What does Function(Of T)(ByVal x as Integer) actually mean?

开发者 https://www.devze.com 2022-12-21 07:45 出处:网络
I\'m fairly new to this concept. I see some functions within some code that a开发者_开发百科re:

I'm fairly new to this concept.

I see some functions within some code that a开发者_开发百科re:

Public Function GetDataObjects(Of Customer)(ByVal dataset as DataSet)
 ...
End Function

What exactly does the (Of Customer) do in this instance or mean?


Doesn't the definition look rather like:

Public Function GetDataObjects(Of T)(ByVal dataset as DataSet) as IList<T>
 ...
End Function

And then you use it like

IList(Of Customer) customers = GetDataObjects(Of Customer)(someDataSet)

if so, the Customer provides a real type to substitute for operations where T is used in the GetDataObjects function


It means that this method is generic. It has a single generic parameter named Customer with no constraints.

Can you provide more code for the GetDataObjects method so we can add a better explanation?


Without seeing the portion of the function that returns a value, it appears to mean that the return type of the function is Customer.

What you're seeing is one of VB.NET's ways of handling Generics.

John

(I could be wrong though. It's been a while since I did VB.NET work.)

Edit

This is not a return type. (Sorry for the confusion.) It merely provides information to the function that "Customer" should be treated as a specific type. Customer becomes a "parameter" defining a type. It could be Integer, String, Object, Decimal, or any other type. (This is all basic Generics.)

Presumably, the function uses this type somehow, but the signature doesn't show the use. (One guess is that the type, temporarily labeled "Customer", is used to determine what columns should be in the dataset or how to use those columns.)

0

精彩评论

暂无评论...
验证码 换一张
取 消