{"id":1954,"date":"2024-10-31T15:32:11","date_gmt":"2024-10-31T13:32:11","guid":{"rendered":"https:\/\/epicmarketing.co.il\/notebook\/?p=1954"},"modified":"2024-10-31T16:48:16","modified_gmt":"2024-10-31T14:48:16","slug":"modern-c-features","status":"publish","type":"post","link":"https:\/\/epicmarketing.co.il\/notebook\/modern-c-features\/","title":{"rendered":"Modern C# Features"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Learning Objectives<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Understand features introduced after C# 6, such as nullable reference types, pattern matching, records, and tuples.<\/li>\n\n\n\n<li>Learn how to use asynchronous programming with <code>async<\/code> and <code>await<\/code>.<\/li>\n\n\n\n<li>Apply modern C# features to enhance code readability, reliability, and performance.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">C# Version Updates<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">Nullable Reference Types<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"> In earlier versions of C#, reference types could be <code>null<\/code> by default, often leading to runtime errors (null reference exceptions). Starting with C# 8, <strong>nullable reference types<\/strong> were introduced to provide better null safety.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You can declare a reference type as nullable (<code>string? name<\/code>) or non-nullable (<code>string name<\/code>).<\/li>\n\n\n\n<li>This feature helps in catching potential null issues during compile time.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Example<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nstring? name = null;\nif (name != null)\n{\n    Console.WriteLine(name.Length);\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong><span style=\"text-decoration: underline;\">Real-Life Example<\/span><\/strong>: In a user management system, ensuring fields like email are non-nullable helps prevent runtime errors when accessing user data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Pattern Matching<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Pattern matching helps simplify complex conditional logic by allowing you to match an object against a set of patterns.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Introduced in C# 7, this feature has been enhanced over versions to support <strong>switch expressions<\/strong>, <strong>type patterns<\/strong>, and <strong>relational patterns<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Code Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nobject value = 42;\nif (value is int number &amp;&amp; number &gt; 0)\n{\n    Console.WriteLine($&quot;The number is {number}&quot;);\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>Real-Life Example<\/strong>: In an e-commerce application, pattern matching can be used to validate different types of payment methods before processing a transaction.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Records<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">were introduced in C# 9 to simplify creating data-carrying classes. Unlike traditional classes, records provide value-based equality and can be easily used to represent immutable data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">They are especially useful for storing data that doesn\u2019t need to change after initialization.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Code Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic record Product(string Name, decimal Price);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>Real-Life Example<\/strong>: In an e-commerce system, you can use records to represent product data that doesn\u2019t change, such as the name and price of an item.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Tuples<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Tuples provide an easy way to store multiple values without creating a separate class. C# 7 introduced improved <strong>value tuples<\/strong> that support better deconstruction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Code Example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nvar product = (Name: &quot;Laptop&quot;, Price: 1200.00M);\nConsole.WriteLine($&quot;Product: {product.Name}, Price: {product.Price}&quot;);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>Real-Life Example<\/strong>: Use tuples to return multiple values from a method, such as returning product details and availability status in a single call.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Asynchronous Programming<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Async\/Await<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Asynchronous programming is key for building responsive and scalable APIs. Using <code>async<\/code> and <code>await<\/code> allows you to run time-consuming operations without blocking the main thread.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>Task<\/strong><\/code>: Represents an ongoing operation that will complete in the future.<\/li>\n\n\n\n<li><code><strong>await<\/strong><\/code>: Ensures that the method is paused until the awaited task completes, allowing the application to remain responsive.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Code Example<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic async Task&lt;string&gt; GetProductAsync(int id)\n{\n    await Task.Delay(1000); \/\/ Simulate async work, like a database call\n    return $&quot;Product {id}&quot;;\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>Real-Life Example<\/strong>: In a financial application, <code>async\/await<\/code> can be used for querying transaction details, ensuring the user interface stays responsive while waiting for server responses.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Best Practices for Asynchronous Programming<\/strong>:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Avoid Blocking Calls<\/strong>: Avoid using <code>.Wait()<\/code> or <code>.Result()<\/code> in async code as it may lead to deadlocks.<\/li>\n\n\n\n<li><strong>Use <\/strong><code><strong>ConfigureAwait(false)<\/strong><\/code> when awaiting in library code to prevent capturing the calling context, thus avoiding potential deadlocks.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Examples<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Pattern Matching with Switch Expressions<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use a switch expression with pattern matching to determine discounts based on customer type.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Code Snippet:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npublic decimal GetDiscount(object customer)\n{\n    return customer switch\n    {\n        RegularCustomer =&gt; 0.05m,\n        PremiumCustomer =&gt; 0.10m,\n        Employee =&gt; 0.15m,\n        _ =&gt; 0.00m\n    };\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The GetDiscount method takes an object named customer as its parameter and determines the discount percentage based on the type of the customer. It uses a switch expression with pattern matching to identify the customer type and return the appropriate discount.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The method checks if the <code>customer<\/code> is an instance of certain types, like <code>RegularCustomer<\/code>, <code>PremiumCustomer<\/code>, or <code>Employee<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each type has a corresponding discount value:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>RegularCustomer<\/strong> gets a <strong>5%<\/strong> discount (<code>0.05m<\/code>).<\/li>\n\n\n\n<li><strong>PremiumCustomer<\/strong> gets a <strong>10%<\/strong> discount (<code>0.10m<\/code>).<\/li>\n\n\n\n<li><strong>Employee<\/strong> gets a <strong>15%<\/strong> discount (<code>0.15m<\/code>).<\/li>\n\n\n\n<li>If the customer doesn't match any of these types, the default case (<code>_<\/code>) returns a discount of <strong>0%<\/strong> (<code>0.00m<\/code>).<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong><code>m<\/code><\/strong> after the numeric values indicate that the number is a <strong>decimal<\/strong> type, which is often used in financial calculations for precision.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Classes for Different Customer Types<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">For this method to work, we need classes to represent the different customer types (<code>RegularCustomer<\/code>, <code>PremiumCustomer<\/code>, <code>Employee<\/code>):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic class RegularCustomer\n{\n    public string Name { get; set; }\n    public RegularCustomer(string name) =&gt; Name = name;\n}\n\npublic class PremiumCustomer\n{\n    public string Name { get; set; }\n    public PremiumCustomer(string name) =&gt; Name = name;\n}\n\npublic class Employee\n{\n    public string Name { get; set; }\n    public Employee(string name) =&gt; Name = name;\n}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">Context and Example Usage<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s say you have a shopping scenario where you want to apply discounts based on the type of customer making the purchase.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> Below is an example of how you might call the <code>GetDiscount<\/code> method.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic class Program\n{\n    public static void Main()\n    {\n        \/\/ Creating instances of different customer types\n        var regularCustomer = new RegularCustomer(&quot;Alice&quot;);\n        var premiumCustomer = new PremiumCustomer(&quot;Bob&quot;);\n        var employee = new Employee(&quot;Charlie&quot;);\n\n        \/\/ Creating an instance of the discount calculator\n        var discountCalculator = new DiscountCalculator();\n\n        \/\/ Calling GetDiscount for different customers\n        decimal regularCustomerDiscount = discountCalculator.GetDiscount(regularCustomer);\n        decimal premiumCustomerDiscount = discountCalculator.GetDiscount(premiumCustomer);\n        decimal employeeDiscount = discountCalculator.GetDiscount(employee);\n\n        \/\/ Outputting the discount values\n        Console.WriteLine($&quot;Regular customer discount: {regularCustomerDiscount * 100}%&quot;);\n        Console.WriteLine($&quot;Premium customer discount: {premiumCustomerDiscount * 100}%&quot;);\n        Console.WriteLine($&quot;Employee discount: {employeeDiscount * 100}%&quot;);\n    }\n}\n\npublic class DiscountCalculator\n{\n    public decimal GetDiscount(object customer)\n    {\n        return customer switch\n        {\n            RegularCustomer =&gt; 0.05m,\n            PremiumCustomer =&gt; 0.10m,\n            Employee =&gt; 0.15m,\n            _ =&gt; 0.00m\n        };\n    }\n}\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\"><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">Key Takeaways<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Modern C# features, like <strong>nullable reference types<\/strong>, <strong>pattern matching<\/strong>, and <strong>records<\/strong>, help improve code quality, readability, and safety.<\/li>\n\n\n\n<li><strong>Async\/await<\/strong> is crucial for building scalable, non-blocking APIs.<\/li>\n\n\n\n<li>Applying these features in real-world examples, such as e-commerce or user management, shows their value in professional projects.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Practical Questions<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>What is the purpose of nullable reference types, and how do they improve code safety?<\/li>\n\n\n\n<li>How can pattern matching simplify conditional logic in your code?<\/li>\n\n\n\n<li>What are the benefits of using <code>async\/await<\/code> for API development?<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Learning Objectives C# Version Updates Nullable Reference Types In earlier versions of C#, reference types could be null by default, often leading to runtime errors (null reference exceptions). Starting with C# 8, nullable reference types were introduced to provide better null safety. Code Example: Real-Life Example: In a user management system, ensuring fields like email [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":""},"categories":[79],"tags":[],"class_list":["post-1954","post","type-post","status-publish","format-standard","hentry","category-dotnet-8","entry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Modern C# Features - Code Notebook<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/epicmarketing.co.il\/notebook\/modern-c-features\/\" \/>\n<meta property=\"og:locale\" content=\"he_IL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Modern C# Features - Code Notebook\" \/>\n<meta property=\"og:description\" content=\"Learning Objectives C# Version Updates Nullable Reference Types In earlier versions of C#, reference types could be null by default, often leading to runtime errors (null reference exceptions). Starting with C# 8, nullable reference types were introduced to provide better null safety. Code Example: Real-Life Example: In a user management system, ensuring fields like email [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/epicmarketing.co.il\/notebook\/modern-c-features\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Notebook\" \/>\n<meta property=\"article:published_time\" content=\"2024-10-31T13:32:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-31T14:48:16+00:00\" \/>\n<meta name=\"author\" content=\"kerendanino\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u05e0\u05db\u05ea\u05d1 \u05e2\u05dc \u05d9\u05d3\" \/>\n\t<meta name=\"twitter:data1\" content=\"kerendanino\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u05d6\u05de\u05df \u05e7\u05e8\u05d9\u05d0\u05d4 \u05de\u05d5\u05e2\u05e8\u05da\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u05d3\u05e7\u05d5\u05ea\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/modern-c-features\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/modern-c-features\\\/\"},\"author\":{\"name\":\"kerendanino\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#\\\/schema\\\/person\\\/195dfc625818eadda7903d456890e24c\"},\"headline\":\"Modern C# Features\",\"datePublished\":\"2024-10-31T13:32:11+00:00\",\"dateModified\":\"2024-10-31T14:48:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/modern-c-features\\\/\"},\"wordCount\":694,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#organization\"},\"articleSection\":[\"Dotnet 8\"],\"inLanguage\":\"he-IL\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/modern-c-features\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/modern-c-features\\\/\",\"url\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/modern-c-features\\\/\",\"name\":\"Modern C# Features - Code Notebook\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#website\"},\"datePublished\":\"2024-10-31T13:32:11+00:00\",\"dateModified\":\"2024-10-31T14:48:16+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/modern-c-features\\\/#breadcrumb\"},\"inLanguage\":\"he-IL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/modern-c-features\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/modern-c-features\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Modern C# Features\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#website\",\"url\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/\",\"name\":\"Code Notebook\",\"description\":\"Easy coding\",\"publisher\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"he-IL\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#organization\",\"name\":\"Code Notebook\",\"url\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"he-IL\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo-epic-marketing-05.png\",\"contentUrl\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/wp-content\\\/uploads\\\/2023\\\/07\\\/logo-epic-marketing-05.png\",\"width\":3626,\"height\":1942,\"caption\":\"Code Notebook\"},\"image\":{\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/#\\\/schema\\\/person\\\/195dfc625818eadda7903d456890e24c\",\"name\":\"kerendanino\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"he-IL\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/285cc9389c66aa46da1e26a474b1e90e9efaf3fa21f1b928cbd63ce5f0e89c63?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/285cc9389c66aa46da1e26a474b1e90e9efaf3fa21f1b928cbd63ce5f0e89c63?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/285cc9389c66aa46da1e26a474b1e90e9efaf3fa21f1b928cbd63ce5f0e89c63?s=96&d=mm&r=g\",\"caption\":\"kerendanino\"},\"url\":\"https:\\\/\\\/epicmarketing.co.il\\\/notebook\\\/author\\\/kerendanino\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Modern C# Features - Code Notebook","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:\/\/epicmarketing.co.il\/notebook\/modern-c-features\/","og_locale":"he_IL","og_type":"article","og_title":"Modern C# Features - Code Notebook","og_description":"Learning Objectives C# Version Updates Nullable Reference Types In earlier versions of C#, reference types could be null by default, often leading to runtime errors (null reference exceptions). Starting with C# 8, nullable reference types were introduced to provide better null safety. Code Example: Real-Life Example: In a user management system, ensuring fields like email [&hellip;]","og_url":"https:\/\/epicmarketing.co.il\/notebook\/modern-c-features\/","og_site_name":"Code Notebook","article_published_time":"2024-10-31T13:32:11+00:00","article_modified_time":"2024-10-31T14:48:16+00:00","author":"kerendanino","twitter_card":"summary_large_image","twitter_misc":{"\u05e0\u05db\u05ea\u05d1 \u05e2\u05dc \u05d9\u05d3":"kerendanino","\u05d6\u05de\u05df \u05e7\u05e8\u05d9\u05d0\u05d4 \u05de\u05d5\u05e2\u05e8\u05da":"4 \u05d3\u05e7\u05d5\u05ea"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/epicmarketing.co.il\/notebook\/modern-c-features\/#article","isPartOf":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/modern-c-features\/"},"author":{"name":"kerendanino","@id":"https:\/\/epicmarketing.co.il\/notebook\/#\/schema\/person\/195dfc625818eadda7903d456890e24c"},"headline":"Modern C# Features","datePublished":"2024-10-31T13:32:11+00:00","dateModified":"2024-10-31T14:48:16+00:00","mainEntityOfPage":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/modern-c-features\/"},"wordCount":694,"commentCount":0,"publisher":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/#organization"},"articleSection":["Dotnet 8"],"inLanguage":"he-IL","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/epicmarketing.co.il\/notebook\/modern-c-features\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/epicmarketing.co.il\/notebook\/modern-c-features\/","url":"https:\/\/epicmarketing.co.il\/notebook\/modern-c-features\/","name":"Modern C# Features - Code Notebook","isPartOf":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/#website"},"datePublished":"2024-10-31T13:32:11+00:00","dateModified":"2024-10-31T14:48:16+00:00","breadcrumb":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/modern-c-features\/#breadcrumb"},"inLanguage":"he-IL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/epicmarketing.co.il\/notebook\/modern-c-features\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/epicmarketing.co.il\/notebook\/modern-c-features\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/epicmarketing.co.il\/notebook\/"},{"@type":"ListItem","position":2,"name":"Modern C# Features"}]},{"@type":"WebSite","@id":"https:\/\/epicmarketing.co.il\/notebook\/#website","url":"https:\/\/epicmarketing.co.il\/notebook\/","name":"Code Notebook","description":"Easy coding","publisher":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/epicmarketing.co.il\/notebook\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"he-IL"},{"@type":"Organization","@id":"https:\/\/epicmarketing.co.il\/notebook\/#organization","name":"Code Notebook","url":"https:\/\/epicmarketing.co.il\/notebook\/","logo":{"@type":"ImageObject","inLanguage":"he-IL","@id":"https:\/\/epicmarketing.co.il\/notebook\/#\/schema\/logo\/image\/","url":"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/07\/logo-epic-marketing-05.png","contentUrl":"https:\/\/epicmarketing.co.il\/notebook\/wp-content\/uploads\/2023\/07\/logo-epic-marketing-05.png","width":3626,"height":1942,"caption":"Code Notebook"},"image":{"@id":"https:\/\/epicmarketing.co.il\/notebook\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/epicmarketing.co.il\/notebook\/#\/schema\/person\/195dfc625818eadda7903d456890e24c","name":"kerendanino","image":{"@type":"ImageObject","inLanguage":"he-IL","@id":"https:\/\/secure.gravatar.com\/avatar\/285cc9389c66aa46da1e26a474b1e90e9efaf3fa21f1b928cbd63ce5f0e89c63?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/285cc9389c66aa46da1e26a474b1e90e9efaf3fa21f1b928cbd63ce5f0e89c63?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/285cc9389c66aa46da1e26a474b1e90e9efaf3fa21f1b928cbd63ce5f0e89c63?s=96&d=mm&r=g","caption":"kerendanino"},"url":"https:\/\/epicmarketing.co.il\/notebook\/author\/kerendanino\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/posts\/1954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/comments?post=1954"}],"version-history":[{"count":4,"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/posts\/1954\/revisions"}],"predecessor-version":[{"id":1962,"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/posts\/1954\/revisions\/1962"}],"wp:attachment":[{"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/media?parent=1954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/categories?post=1954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/epicmarketing.co.il\/notebook\/wp-json\/wp\/v2\/tags?post=1954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}