{"id":4219,"date":"2018-08-03T07:51:35","date_gmt":"2018-08-03T06:51:35","guid":{"rendered":"https:\/\/code-maze.com\/?p=4219"},"modified":"2021-12-16T11:45:54","modified_gmt":"2021-12-16T10:45:54","slug":"csharp-type-conversion","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-type-conversion\/","title":{"rendered":"Type Conversion in C#"},"content":{"rendered":"<p>In C#, data can be converted from one type to another by using an implicit conversion (automatic) or an explicit conversion (we can choose how it\u2019s done).<\/p>\n<ul id=\"series_parts\" style=\"display: none;\">\n<li><a href=\"https:\/\/code-maze.com\/csharp-basics-ide-introduction\/\" target=\"_blank\" rel=\"noopener noreferrer\">Development Environment Setup<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-basics-data-types-variables\/\" target=\"_blank\" rel=\"noopener noreferrer\">Data Types, Declarations and Variable Definitions<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-basics-operators\/\" target=\"_blank\" rel=\"noopener noreferrer\">Operators in C#<\/a><\/li>\n<li>Type Conversion (Current article)<\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-basics-input-output\/\" target=\"_blank\" rel=\"noopener noreferrer\">Input and Output in C#<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-basics-string-methods\/\" target=\"_blank\" rel=\"noopener noreferrer\">Working with Strings<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-basics-conditions\/\" target=\"_blank\" rel=\"noopener noreferrer\">Conditions in C# (If, If-Else, If-ElseIf, Switch-Case)<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-basics-loops\/\" target=\"_blank\" rel=\"noopener noreferrer\">Loops(While, Do-While, For)<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-basics-handling-exceptions\/\" target=\"_blank\" rel=\"noopener noreferrer\">Handling Exceptions<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-basics-access-modifiers\/\" target=\"_blank\" rel=\"noopener noreferrer\">Access Modifiers<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-basics-methods\/\" target=\"_blank\" rel=\"noopener noreferrer\">Methods<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/cshrap-basics-ref-out-keywords\/\" target=\"_blank\" rel=\"noopener noreferrer\">Ref and Out Keywords<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-basics-recursion\/\" target=\"_blank\" rel=\"noopener noreferrer\">Recursion and Recursive Methods<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-basics-arrays\/\" target=\"_blank\" rel=\"noopener noreferrer\">Arrays (single-dimensional and multi-dimensional arrays)<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-basics-streamwriter-streamreader\/\" target=\"_blank\" rel=\"noopener noreferrer\">Working with Files, StreamWriter and StreamReader<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-basics-file-directory\/\" target=\"_blank\" rel=\"noopener noreferrer\">Working with Files, File, and Directory<\/a><\/li>\n<\/ul>\n<p>For the complete navigation of this series check out: <a href=\"https:\/\/code-maze.com\/csharp-back-to-basics\/\" target=\"_blank\" rel=\"noopener noreferrer\">C# Back to Basics.<\/a><\/p>\n<p>In this article, we are going to cover:<\/p>\n<ul>\n<li><a href=\"#implicit\">Implicit Conversion in C#<\/a><\/li>\n<li><a href=\"#explicit\">Explicit Conversion in C#<\/a><\/li>\n<li><a href=\"#convertclass\">Using the Convert Class in C#<\/a><\/li>\n<li><a href=\"#conclusion\">Conclusion<\/a><\/li>\n<\/ul>\n<p>So, let&#8217;s talk more about that.<\/p>\n<h2 id=\"implicit\">Implicit Conversion in C#<\/h2>\n<p>Many different data could be interpreted by using different types. For example, the number 74 can be interpreted as an integer but also as double (74.0). There are two situations in which implicit conversion applies.<\/p>\n<p>The first one is when we calculate an expression. The compiler automatically adapts data types that we use in that expression:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">class Program\r\n{\r\n    static void Main(string[] args)\r\n    {\r\n        double b = 12.45;\r\n        int x = 10;\r\n        b = b + x;\r\n    }\r\n}\r\n<\/pre>\n<p>Here the <code>b<\/code> variable is of type double and <code>x<\/code> is of type int. In the expression <code>b + x<\/code>, the compiler implicitly converts <code>x<\/code> from int to double and then it assigns a result to the <code>b<\/code>.<\/p>\n<p>The second situation for conversion is when the compiler stores the result to a variable:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">class Program\r\n{\r\n    static void Main(string[] args)\r\n    {\r\n        int y = 20;\r\n        int x = 10;\r\n        double b;\r\n        b = y \/ x;\r\n    }\r\n}<\/pre>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/10-Implicit-Conversion-e1639651040773.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4220 size-full\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/10-Implicit-Conversion-e1639651040773.png\" alt=\"Implicit Conversion C# Type Conversions\" width=\"402\" height=\"56\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/10-Implicit-Conversion-e1639651040773.png 402w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/10-Implicit-Conversion-e1639651040773-300x42.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/10-Implicit-Conversion-e1639651040773-400x56.png 400w\" sizes=\"auto, (max-width: 402px) 100vw, 402px\" \/><\/a><\/p>\n<p>In this example, we see that both <code>x<\/code> and\u00a0<code>y<\/code> are of the type int, but the result is of the type double.<\/p>\n<p>Now, let&#8217;s pay attention to this example:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">int x = 21;\r\nint y = 5\r\n\r\ndouble b = x\/y;<\/pre>\n<p>What do you think, which value is stored in the variable\u00a0<code>b<\/code>?<\/p>\n<p>The answer: &#8220;The result is 4.2&#8221; is not correct. Of course, now goes the question: &#8220;But why&#8221;?<\/p>\n<p>The compiler calculates the right-side expression first and only then converts that result into double. So, the right side expression <code>x\/y<\/code>consist of integer numbers, thus the result is an integer number as well, in this example, it is 4 (the value is truncated). After that calculation, the compiler converts the result into a double and assigns the value to the b variable:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">class Program\r\n{\r\n    static void Main(string[] args)\r\n    {\r\n        int y = 5;\r\n        int x = 21;\r\n        double b = x \/ y;\r\n    }\r\n}<\/pre>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/10.1-Implicit-Conversion2-e1639651174218.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4356 size-full\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/10.1-Implicit-Conversion2-e1639651174218.png\" alt=\"implicit conversion 2\" width=\"575\" height=\"81\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/10.1-Implicit-Conversion2-e1639651174218.png 575w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/10.1-Implicit-Conversion2-e1639651174218-300x42.png 300w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/><\/a><\/p>\n<p>We can fix this if we want, by using the explicit conversion on either <code>x<\/code> or <code>y<\/code> variable in the expression.<\/p>\n<h2 id=\"explicit\">Explicit Conversion in C#<\/h2>\n<p>For the explicit conversion, we need to write additional code to convert one type to another. We have two different ways, by using a cast operator or by using the <code>Convert<\/code> class.<\/p>\n<p>Let&#8217;s look at the following example:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/11-Missing_cast.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4221\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/11-Missing_cast.png\" alt=\"Missing Cast C# Type Conversions\" width=\"684\" height=\"203\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/11-Missing_cast.png 684w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/11-Missing_cast-600x178.png 600w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/11-Missing_cast-300x89.png 300w\" sizes=\"auto, (max-width: 684px) 100vw, 684px\" \/><\/a><\/p>\n<p>The compiler complains about an invalid conversion. What we are missing here is the cast operator, so let&#8217;s use it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">class Program\r\n{\r\n    static void Main(string[] args)\r\n    {\r\n        int a;\r\n        double b = 10.7;\r\n\r\n        a = (int)b;\r\n    }\r\n}<\/pre>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/12-Success_cast.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4222 size-full\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/12-Success_cast-e1639651312582.png\" alt=\"Success cast C# Type Conversions\" width=\"397\" height=\"81\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/12-Success_cast-e1639651312582.png 397w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/07\/12-Success_cast-e1639651312582-300x61.png 300w\" sizes=\"auto, (max-width: 397px) 100vw, 397px\" \/><\/a><\/p>\n<p>By using the cast <code>(int)<\/code>conversion, we can safely cast our data types and the compiler approves of that. But what we can see is that our result is not what we would expect it to be. But this is the correct result. It is very important to understand that the cast operator can shrink data when we convert the type with the larger value scope to a type with the smaller value scope. Like we did with the double to int conversion for example.<\/p>\n<p>Now we can apply the cast operator on our example from the Implicit Conversion part, to get the right result:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">class Program\r\n{\r\n    static void Main(string[] args)\r\n    {\r\n        int x = 21;\r\n        int y = 5;\r\n\r\n        double b = (double)x \/ y;\r\n    }\r\n}<\/pre>\n<p>The result is going to be 4.2.<\/p>\n<h2 id=\"convertclass\">Using the Convert Class in C#<\/h2>\n<p>As we said, we can use the Convert class with its static methods, to explicitly convert one base type to another base type:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">class Program\r\n{\r\n    static void Main(string[] args)\r\n    {\r\n        int a = 15;\r\n        string s = a; \/\/ this is not allowed\r\n\r\n        int c = 15;\r\n        string s1 = Convert.ToString(c); \r\n        \/\/or\r\n        string s2 = c.ToString();\r\n\r\n    }\r\n}<\/pre>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>We have learned about type conversion and how implicit and explicit conversion behaves in C#.<\/p>\n<p>In <a href=\"https:\/\/code-maze.com\/csharp-basics-input-output\/\" target=\"_blank\" rel=\"noopener noreferrer\">the next post<\/a>, we are going to talk about Linear Structures in C#.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In C#, data can be converted from one type to another by using an implicit conversion (automatic) or an explicit conversion (we can choose how it\u2019s done). Development Environment Setup Data Types, Declarations and Variable Definitions Operators in C# Type Conversion (Current article) Input and Output in C# Working with Strings Conditions in C# (If, [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":54450,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[505,12],"tags":[235,232,234,233,40],"class_list":["post-4219","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-basic","category-csharp","tag-cast","tag-conversion","tag-explicit-conversion","tag-implicit-conversion","tag-visual-studio-2017","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C# Type Conversions (Implicit and Explicit Conversion) - Code Maze<\/title>\n<meta name=\"description\" content=\"Learn about C# Type Conversions, how to use implicite and explicite conversion. Practice through examples in this article.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/csharp-type-conversion\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C# Type Conversions (Implicit and Explicit Conversion) - Code Maze\" \/>\n<meta property=\"og:description\" content=\"Learn about C# Type Conversions, how to use implicite and explicite conversion. Practice through examples in this article.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-type-conversion\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-03T06:51:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-16T10:45:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/04-type-conversion.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Marinko Spasojevi\u0107\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Marinko Spasojevi\u0107\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/csharp-type-conversion\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-type-conversion\/\"},\"author\":{\"name\":\"Marinko Spasojevi\u0107\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533\"},\"headline\":\"Type Conversion in C#\",\"datePublished\":\"2018-08-03T06:51:35+00:00\",\"dateModified\":\"2021-12-16T10:45:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-type-conversion\/\"},\"wordCount\":612,\"commentCount\":6,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-type-conversion\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/04-type-conversion.png\",\"keywords\":[\"Cast\",\"Conversion\",\"Explicit Conversion\",\"Implicit Conversion\",\"Visual Studio 2017\"],\"articleSection\":[\"Basic\",\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-type-conversion\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-type-conversion\/\",\"url\":\"https:\/\/code-maze.com\/csharp-type-conversion\/\",\"name\":\"C# Type Conversions (Implicit and Explicit Conversion) - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-type-conversion\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-type-conversion\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/04-type-conversion.png\",\"datePublished\":\"2018-08-03T06:51:35+00:00\",\"dateModified\":\"2021-12-16T10:45:54+00:00\",\"description\":\"Learn about C# Type Conversions, how to use implicite and explicite conversion. Practice through examples in this article.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-type-conversion\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-type-conversion\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-type-conversion\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/04-type-conversion.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/04-type-conversion.png\",\"width\":1100,\"height\":620,\"caption\":\"04 type conversion\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/csharp-type-conversion\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Type Conversion in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533\",\"name\":\"Marinko Spasojevi\u0107\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg\",\"caption\":\"Marinko Spasojevi\u0107\"},\"description\":\"Hi, my name is Marinko Spasojevic. Currently, I work as a full-time .NET developer and my passion is web application development. Just getting something to work is not enough for me. To make it just how I like it, it must be readable, reusable, and easy to maintain. Prior to being an author on the CodeMaze blog, I had been working as a professor of Computer Science for several years. So, sharing knowledge while working as a full-time developer comes naturally to me.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/marinko-spasojevic\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/marinko\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C# Type Conversions (Implicit and Explicit Conversion) - Code Maze","description":"Learn about C# Type Conversions, how to use implicite and explicite conversion. Practice through examples in this article.","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:\/\/code-maze.com\/csharp-type-conversion\/","og_locale":"en_US","og_type":"article","og_title":"C# Type Conversions (Implicit and Explicit Conversion) - Code Maze","og_description":"Learn about C# Type Conversions, how to use implicite and explicite conversion. Practice through examples in this article.","og_url":"https:\/\/code-maze.com\/csharp-type-conversion\/","og_site_name":"Code Maze","article_published_time":"2018-08-03T06:51:35+00:00","article_modified_time":"2021-12-16T10:45:54+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/04-type-conversion.png","type":"image\/png"}],"author":"Marinko Spasojevi\u0107","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Marinko Spasojevi\u0107","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-type-conversion\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-type-conversion\/"},"author":{"name":"Marinko Spasojevi\u0107","@id":"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533"},"headline":"Type Conversion in C#","datePublished":"2018-08-03T06:51:35+00:00","dateModified":"2021-12-16T10:45:54+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-type-conversion\/"},"wordCount":612,"commentCount":6,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-type-conversion\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/04-type-conversion.png","keywords":["Cast","Conversion","Explicit Conversion","Implicit Conversion","Visual Studio 2017"],"articleSection":["Basic","C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-type-conversion\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-type-conversion\/","url":"https:\/\/code-maze.com\/csharp-type-conversion\/","name":"C# Type Conversions (Implicit and Explicit Conversion) - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-type-conversion\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-type-conversion\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/04-type-conversion.png","datePublished":"2018-08-03T06:51:35+00:00","dateModified":"2021-12-16T10:45:54+00:00","description":"Learn about C# Type Conversions, how to use implicite and explicite conversion. Practice through examples in this article.","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-type-conversion\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-type-conversion\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-type-conversion\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/04-type-conversion.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/08\/04-type-conversion.png","width":1100,"height":620,"caption":"04 type conversion"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/csharp-type-conversion\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Type Conversion in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533","name":"Marinko Spasojevi\u0107","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg","caption":"Marinko Spasojevi\u0107"},"description":"Hi, my name is Marinko Spasojevic. Currently, I work as a full-time .NET developer and my passion is web application development. Just getting something to work is not enough for me. To make it just how I like it, it must be readable, reusable, and easy to maintain. Prior to being an author on the CodeMaze blog, I had been working as a professor of Computer Science for several years. So, sharing knowledge while working as a full-time developer comes naturally to me.","sameAs":["https:\/\/www.linkedin.com\/in\/marinko-spasojevic\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/marinko\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/4219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=4219"}],"version-history":[{"count":3,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/4219\/revisions"}],"predecessor-version":[{"id":61615,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/4219\/revisions\/61615"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/54450"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=4219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=4219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=4219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}