Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting Columns from LINQ List
Message
From
03/07/2011 19:47:35
 
 
To
03/07/2011 19:00:42
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01517212
Message ID:
01517227
Views:
32
>ooohhhh keyyyyyy
>
>Can Someone explain that one to me?
>
>You are correct the design plattform does not show an error anymore. I'll have to test the whole code now to see if I run into any other errors.
>
>But I don't understand that.
>
>I know that the "(of T)" expects a type (such as integer, varchar, etc...
>
>since "T" is not a type I understood the occurance of the error - just didn't know how to fix it.
>
>But all you did was to add another "(Of T)" - now i am defently lost.
>
>I was already way lost before - but now ... lol


You're right that "(Of T)" in VB or "< T >" in C#, tells the the compiler to expect a type. However, you hadn't told the method to expect the type, and it was only "mentioned" in the parameter list, so the compiler didn't know what to expect and thought that type T was undefined. It seems a bit redundant to have to specify T in both places and a bit silly that the compiler couldn't infer that, but that's the way it is with generics.

So, the first use of "(Of T)" tells the method to expect a type T, whereas the second use of it, tells the method which parameter is going to make use of the type T:

Public Shared Function ToDataTable(Of T)(data As IList(Of T)) As DataTable

>Thank you much for that help!

You're welcome! I hope the above explanation makes sense. I might have caught the missing "(Of T)" earlier if I knew VB syntax better. <g>

~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform