Using (Of T) generic with functions in Visual Basic 2012

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 9815402440
    New Member
    • Oct 2007
    • 180

    Using (Of T) generic with functions in Visual Basic 2012

    Hi folks,
    can you please explain what (Of T) is after function name in following line:
    Code:
    Public Function StdDev(Of T)( source As IEnumerable(Of T), selector As Func(Of T, Decimal)) As Decimal
    I am using visual basic 2012 .
    I understand that this function will extend IEnumerable(Of T) and gets one delegate as parameter, but I could not get what is (Of T) in this declaration
    Last edited by Rabbit; Nov 14 '13, 03:31 AM. Reason: fixed code tags
  • !NoItAll
    Contributor
    • May 2006
    • 297

    #2
    Of Type
    Lets you set the type.
    A very common use is
    Friend MyList as List(of String)

    MyList is now a list of strings. The List class gives you much more control than a simple array has to offer. For example you can use MyList.add("str ing") to add something to the end of the list or MyList.add("Str ing", 2) to add a new element to index position 3. You can also remove items from the middle, etc and all the management is done for you.

    Comment

    • 9815402440
      New Member
      • Oct 2007
      • 180

      #3
      function is declared as
      StdDev (Of T)( source As IEnumerable(Of T), selector As Func(Of T, Decimal)) As Decimal

      can you please explain what bold text means in the declaration?

      Comment

      Working...