{"id":251,"date":"2013-02-13T11:50:58","date_gmt":"2013-02-13T16:50:58","guid":{"rendered":"http:\/\/binaryworld.net\/blogs\/?p=251"},"modified":"2013-08-13T14:43:12","modified_gmt":"2013-08-13T18:43:12","slug":"nullable-types-in-c-and-vb-net","status":"publish","type":"post","link":"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/","title":{"rendered":"Nullable types in C# and VB.net"},"content":{"rendered":"<p>Have you ever try to assign null to int value in C# or VB<\/p>\n<p>Both language has totally different behavior. VB allows you assign Nothing but it will translate to zero on the other end C# throws error &#8220;type is not nullable&#8221;<\/p>\n<p>Here is how you can set Integer to Null value in Both languages<\/p>\n<h4>Visual basic.net<\/h4>\n<pre class=\"brush: vbnet; gutter: true\">\r\nDim i as Integer=Nothing  &#039;\/\/Works but set i=0\r\nDim i as Integer?=Nothing  &#039;\/\/Works set i=Nothing\r\n<\/pre>\n<h4>C#<\/h4>\n<pre class=\"brush: csharp; gutter: true\">\r\nint i =null &#039;\/\/ERROR: type not nullable\r\nint? i =null &#039;\/\/Works set i=null\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever try to assign null to int value in C# or VB Both language has totally different behavior. VB allows you assign Nothing but it will translate to zero on the other end C# throws error &#8220;type is &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/\"> <span class=\"screen-reader-text\">Nullable types in C# and VB.net<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49,66,61,65],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>Nullable types in C# and VB.net - BinaryWorld Blog<\/title>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"Nullable types in C# and VB.net - BinaryWorld Blog\" \/>\r\n<meta property=\"og:description\" content=\"Have you ever try to assign null to int value in C# or VB Both language has totally different behavior. VB allows you assign Nothing but it will translate to zero on the other end C# throws error &#8220;type is &hellip; Nullable types in C# and VB.net Read More &raquo;\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/\" \/>\r\n<meta property=\"og:site_name\" content=\"BinaryWorld Blog\" \/>\r\n<meta property=\"article:published_time\" content=\"2013-02-13T16:50:58+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2013-08-13T18:43:12+00:00\" \/>\r\n<meta name=\"author\" content=\"Binary World\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Binary World\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/\",\"url\":\"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/\",\"name\":\"Nullable types in C# and VB.net - BinaryWorld Blog\",\"isPartOf\":{\"@id\":\"https:\/\/binaryworld.net\/blogs\/#website\"},\"datePublished\":\"2013-02-13T16:50:58+00:00\",\"dateModified\":\"2013-08-13T18:43:12+00:00\",\"author\":{\"@id\":\"https:\/\/binaryworld.net\/blogs\/#\/schema\/person\/77cf0a9a512dd22bff93c6a1b6374fe0\"},\"breadcrumb\":{\"@id\":\"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/binaryworld.net\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Nullable types in C# and VB.net\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/binaryworld.net\/blogs\/#website\",\"url\":\"https:\/\/binaryworld.net\/blogs\/\",\"name\":\"BinaryWorld Blog\",\"description\":\"Tips and Tutorials for Microsoft SQL Server, SSIS, SSAS, Business Intelligence, C#, .net\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/binaryworld.net\/blogs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/binaryworld.net\/blogs\/#\/schema\/person\/77cf0a9a512dd22bff93c6a1b6374fe0\",\"name\":\"Binary World\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/binaryworld.net\/blogs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eaea47799daa577835eb53e64dfd3e13?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eaea47799daa577835eb53e64dfd3e13?s=96&d=mm&r=g\",\"caption\":\"Binary World\"},\"description\":\"Binary World is a Software Development company located in Atlanta, USA (since 2007). Binary World specialized in Business Intelligence, mobile, cloud computing and .Net Application Development.\",\"url\":\"https:\/\/binaryworld.net\/blogs\/author\/admin\/\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Nullable types in C# and VB.net - BinaryWorld Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/","og_locale":"en_US","og_type":"article","og_title":"Nullable types in C# and VB.net - BinaryWorld Blog","og_description":"Have you ever try to assign null to int value in C# or VB Both language has totally different behavior. VB allows you assign Nothing but it will translate to zero on the other end C# throws error &#8220;type is &hellip; Nullable types in C# and VB.net Read More &raquo;","og_url":"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/","og_site_name":"BinaryWorld Blog","article_published_time":"2013-02-13T16:50:58+00:00","article_modified_time":"2013-08-13T18:43:12+00:00","author":"Binary World","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Binary World"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/","url":"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/","name":"Nullable types in C# and VB.net - BinaryWorld Blog","isPartOf":{"@id":"https:\/\/binaryworld.net\/blogs\/#website"},"datePublished":"2013-02-13T16:50:58+00:00","dateModified":"2013-08-13T18:43:12+00:00","author":{"@id":"https:\/\/binaryworld.net\/blogs\/#\/schema\/person\/77cf0a9a512dd22bff93c6a1b6374fe0"},"breadcrumb":{"@id":"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/binaryworld.net\/blogs\/nullable-types-in-c-and-vb-net\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/binaryworld.net\/blogs\/"},{"@type":"ListItem","position":2,"name":"Nullable types in C# and VB.net"}]},{"@type":"WebSite","@id":"https:\/\/binaryworld.net\/blogs\/#website","url":"https:\/\/binaryworld.net\/blogs\/","name":"BinaryWorld Blog","description":"Tips and Tutorials for Microsoft SQL Server, SSIS, SSAS, Business Intelligence, C#, .net","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/binaryworld.net\/blogs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/binaryworld.net\/blogs\/#\/schema\/person\/77cf0a9a512dd22bff93c6a1b6374fe0","name":"Binary World","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/binaryworld.net\/blogs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/eaea47799daa577835eb53e64dfd3e13?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eaea47799daa577835eb53e64dfd3e13?s=96&d=mm&r=g","caption":"Binary World"},"description":"Binary World is a Software Development company located in Atlanta, USA (since 2007). Binary World specialized in Business Intelligence, mobile, cloud computing and .Net Application Development.","url":"https:\/\/binaryworld.net\/blogs\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/posts\/251"}],"collection":[{"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/comments?post=251"}],"version-history":[{"count":0,"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/posts\/251\/revisions"}],"wp:attachment":[{"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/media?parent=251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/categories?post=251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/tags?post=251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}