VB.NET: What is static T (C #) in VB.NET?

Consider:

public static T GetValueOrDefault<T>(this IDataReader reader, string columnName)

 T returnValue = default(T);

I want to implement something like this to check for DBNull. I can keep track of the code well, but I don’t quite understand what static T is in VB.NET. Can someone explain this a bit?

+5
source share
6 answers

Equivalent staticto VB's Shared. General methods are usually placed in Helper classes because they do not need an instance of the class to run.

Type T indicates that this is a general method (this is a new feature in VB 9 and C # 3). A generic method effectively takes a type as an argument or returns a generic type.

VB: 9/# 3. , . , , Shared, , , VB , .

- , , , . Module class. VB.

( , , " ", Nothing, VB ).

Imports System.Runtime.CompilerServices
<Extension()> _
Public Shared Function GetValueOrDefault(Of T)(ByVal reader As IDataReader, ByVal columnName As String) As T
Dim returnValue As T = Nothing

End Function
+11

. # (Shared Visual Basic).

Visual Basic, -, , #. , MSDN , : http://msdn.microsoft.com/en-us/library/bb384936.aspx

+1

VB:

Imports System.Runtime.CompilerServices 

<Extension()> _
Public Shared Function GetValueOrDefault(Of T)(ByVal reader As IDataReader, ByVal columnName As String) as T
    Dim returnvalue As T = Nothing
End Function

, (T) VB, .

+1

, , " T", .

  • public , .
  • static . , , .
  • T - .

.

VB.NET .

.

0

# VB Shared.

0

T in your example is a type parameter in your generic method.

In VB:

Public Function GetValueOrDefault(Of T)(ByVal reader as IDataReader, ByVal columnName as string) as T

Indicates that when calling a method, you specify a type parameter (indicating what type T will be for the method call)

Not sure about VB syntax for creating extension method. (This keyword "this" for your first parameter indicates.)

0
source

All Articles