tags:

views:

45

answers:

3

I'm fairly new to this concept.

I see some functions within some code that are:

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

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

A: 

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.)

John Fisher
So, that's simply a way to show the return type that's different than saying "As Customer"?
jlrolin
@jlrolin - no. Does your code actually compile?
Yes, but I'm looking at it, and it definitely isn't a return. I'm looking at some Generics examples for VB.net now... maybe I'll get a better understanding.
jlrolin
I just modified my answer to provide more and accurate information.
John Fisher
+1  A: 

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?

JaredPar
+1  A: 

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