VB.NET

Collection of snippets I use in my daily programming work

Select Case on an object’s type in VB.NET

Select Case msg.GetType()
    Case GetType(ClassA)
End Select

i18n with Resource Files

Suppose you have the files Strings.resx and Strings.en.resx in you Project, then you can access these Strings in a localized way (depending on the current culture) like this:

Dim _R As Resources.ResourceManager = My.Resources.Strings.ResourceManager
Dim str = _R.GetString("SomeLocalizedResource")

Enums

Convert an int-based enum into its integer representation

Public Enum myEnum
  someValue = 42
End Enum

Dim intValue = Convert.ToInt32(myEnum) 

DataRows and DataTables

Converting a Datatable into an Enumerable

1st Option
collection as IEnumerable(Of DataRow) = myTypedTable.Cast(Of DataRow)();
2nd Option
DataRow() collection = myTypedTable.Select()

More Articles