Women in Technology

Hear us Roar

  New Features in VB.NET — Generics
Subject:   Some missing, but ver useful information
Date:   2006-06-30 08:16:59
From:   mindcore
Ver good article, however the author failed to point out one very important piece of information. Generics in VB.NET are very dangerous if you do not put Option Strict On at the beginning of your code or as your default in the configuration. VB.NET has a tendency to autocast if strict is not on. What does this mean? Well try the following with and without strict on:

Dim list as System.Collections.Generics.Ilist(Of Integer) = New System.Collections.Generics.Ilist(Of Integer)

Dim test1 As Integer = 1<br/>
Dim test2 As String = "2"



NOTE: Change test2's value to an "a" with option strict off and the code will still compile, but you will receive an InvalidCastException at list.Add(test2).