{"id":7493,"date":"2004-05-28T08:08:00","date_gmt":"2004-05-28T08:08:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vbteam\/2004\/05\/28\/nullable-types-in-vb-as-well\/"},"modified":"2024-07-05T15:03:53","modified_gmt":"2024-07-05T22:03:53","slug":"nullable-types-in-vb-as-well","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/vbteam\/nullable-types-in-vb-as-well\/","title":{"rendered":"Nullable types in VB as Well"},"content":{"rendered":"<p><a href=\"http:\/\/weblogs.asp.net\/ericgu\/\">Eric Gunnerson<\/p>\n<p> writes about C# supporting Nullable types.  <br \/>\nWe&#8217;ve heard a lot of positive feedback on the Nullable types.  Just so everyone&#8217;s aware, this is NOT a C# specific feature.  Just as with all generics, VB will both emit and consume the full set of generics, including Nullable types.  <br \/>\nVB has a slightly different syntax, and is a little easier to type as the VS Whidbey Code Editor will auto expand the body:<br \/>\nIf I have an Order object that has a DateShipped property, it would be expressed as:<br \/>\nPublic Class Order<br \/>\nPublic Property OrderId as Integer<br \/>\n&hellip;<br \/>\nPublic Property DateShipped as Nullable(Of DateTime)<br \/>\n&hellip;<\/p>\n<p>When the user types Nullable and hits tab, VB will automatically add &ldquo;(Of &ldquo;.  It just reads more cleanly.  Even reading C#, I would read Nullable Of DateTime.  Now, C# is doing a bit of syntactical sugar and using ? in their syntax as well as Nullable  <br \/>\nPublic class Order<br \/>\n\tpublic int OrderId {get\/set}<br \/>\npublic DateTime? DateShipped {get\/set}<br \/>\nIt is a little strange that VB was historically criticized for supporting multiple ways to do the same thing, and confusing users which was the best.  How about + &amp;.  <br \/>\nThis becomes especially useful when working with Databases and ADO.net<br \/>\nSome of the features we&rsquo;re considering in Beta 2 are the ability to leverage Nullable(Of T) on our new TableAdapter methods.  In the Beta 1 product, as well as the Community Technology Previews you&rsquo;ll see methods generated insert, update, delete and fill.  These have two method signatures.  One strongly typed, and one with the same number of parameters that take object as their type.  This was to support sending Null into the methods.  Unfortunatley, this means you won&rsquo;t get any compile time errors if you pass a string for a column that requires int.  We are looking at moving these overloads to a single method signature:<br \/>\nPublic Function Insert(ByVal id As Nullable(Of Integer), ByVal name As String, ByVal dateClosed As Nullable(Of DateTime)) As Integer<br \/>\nIf dateClosed.HasValue Then<br \/>\n   Me.InsertCommand.Parameters(0).Value = dateClosed.Value<br \/>\nElse<br \/>\n   Me.InsertCommand.Parameters(0).Value = System.Convert.DBNull<br \/>\nEnd If<\/p>\n<p>\nSteve Lasker<br \/>\nProgram Manager<br \/>\nVisual Basic Data \n<\/p>\n<p><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Eric Gunnerson writes about C# supporting Nullable types. We&#8217;ve heard a lot of positive feedback on the Nullable types. Just so everyone&#8217;s aware, this is NOT a C# specific feature. Just as with all generics, VB will both emit and consume the full set of generics, including Nullable types. VB has a slightly different syntax, [&hellip;]<\/p>\n","protected":false},"author":260,"featured_media":8818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[192,195],"tags":[],"class_list":["post-7493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-featured","category-visual-basic"],"acf":[],"blog_post_summary":"<p>Eric Gunnerson writes about C# supporting Nullable types. We&#8217;ve heard a lot of positive feedback on the Nullable types. Just so everyone&#8217;s aware, this is NOT a C# specific feature. Just as with all generics, VB will both emit and consume the full set of generics, including Nullable types. VB has a slightly different syntax, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/7493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/users\/260"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/comments?post=7493"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/posts\/7493\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media\/8818"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/media?parent=7493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/categories?post=7493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/vbteam\/wp-json\/wp\/v2\/tags?post=7493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}