{"appState":{"pageLoadApiCallsStatus":true},"categoryState":{"relatedCategories":{"headers":{"timestamp":"2025-04-17T16:01:06+00:00"},"categoryId":33596,"data":{"title":"C#","slug":"csharp","image":{"src":null,"width":0,"height":0},"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"C#","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"},"slug":"csharp","categoryId":33596}],"parentCategory":{"categoryId":33592,"title":"Programming & Web Design","slug":"programming-web-design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"}},"childCategories":[],"description":"C# (pronounced \"see sharp\") is like C's cooler cousin. Simplified and streamlined, this programming language is still crazy-powerful.","relatedArticles":{"self":"https://dummies-api.dummies.com/v2/articles?category=33596&offset=0&size=5"},"hasArticle":true,"hasBook":true,"articleCount":29,"bookCount":4},"_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"}},"relatedCategoriesLoadedStatus":"success"},"listState":{"list":{"count":10,"total":29,"items":[{"headers":{"creationTime":"2018-01-13T02:14:54+00:00","modifiedTime":"2022-03-10T15:09:12+00:00","timestamp":"2022-09-14T18:19:23+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"C#","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"},"slug":"csharp","categoryId":33596}],"title":"C# 7.0 All-In-One For Dummies Cheat Sheet","strippedTitle":"c# 7.0 all-in-one for dummies cheat sheet","slug":"c-7-0-one-dummies-cheat-sheet","canonicalUrl":"","seo":{"metaDescription":"With C#, you have a wealth of programming options at your fingertips. Take a look at some C# shortcuts, keywords, and templates here.","noIndex":0,"noFollow":0},"content":"C# provides you with access to a phenomenal array of programming options. Use this cheat sheet to help you get the job done faster and easier when using C# as your development solution of choice.","description":"C# provides you with access to a phenomenal array of programming options. Use this cheat sheet to help you get the job done faster and easier when using C# as your development solution of choice.","blurb":"","authors":[{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}},{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}}],"primaryCategoryTaxonomy":{"categoryId":33596,"title":"C#","slug":"csharp","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}},{"articleId":249449,"title":"Using Anonymous Methods in C#","slug":"using-anonymous-methods-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249449"}}],"fromCategory":[{"articleId":289765,"title":"C# 10.0 All-in-One For Dummies Cheat Sheet","slug":"c-10-0-all-in-one-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/289765"}},{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281649,"slug":"c-7-0-all-in-one-for-dummies","isbn":"9781119428114","categoryList":["technology","programming-web-design","csharp"],"amazon":{"default":"https://www.amazon.com/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119428114-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/c-sharp-7.0-all-in-one-for-dummies-cover-9781119428114-203x255.jpg","width":203,"height":255},"title":"C# 7.0 All-in-One For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9109\">John Paul Mueller</b> is a writer on programming topics like AWS, Python, Java, HTML, CSS, and JavaScript. <b data-author-id=\"9786\">William Sempf</b> is a programmer and .NET evangelist. <b data-author-id=\"9787\">Chuck Sphar</b> was a full-time senior technical writer for the Visual C++ product group at Microsoft. </p>","authors":[{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}},{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221b2b1d0f4\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221b2b1da84\"></div></div>"},"articleType":{"articleType":"Cheat Sheet","articleList":[{"articleId":248706,"title":"A Quick Overview of C# 7.0 Web Application Templates","slug":"quick-overview-c-7-0-web-application-templates","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/248706"}},{"articleId":248709,"title":"Common Visual Studio 2017 Keyboard Shortcuts","slug":"common-visual-studio-2017-keyboard-shortcuts","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/248709"}},{"articleId":248712,"title":"C# 7.0 Keyword Listing","slug":"c-7-0-keyword-listing","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/248712"}}],"content":[{"title":"A quick overview of C# 7.0 web application templates","thumb":null,"image":null,"content":"<p>Most developers starting a project today will want to provide web application support, even if the initial application is a desktop application. Users no longer want to be tied to the desktop; they want to spread their wings and use devices of every sort anywhere they want to access their data. The following table provides a list of the kinds of web applications you can build using C# 7.</p>\n<table>\n<tbody>\n<tr>\n<td width=\"128\"><strong>Project Type</strong></td>\n<td width=\"180\"><strong>Supported Environments</strong></td>\n<td width=\"330\"><strong>Description</strong></td>\n</tr>\n<tr>\n<td width=\"128\">ASP.NET Dynamic Data Entries Web Site</td>\n<td width=\"180\">New Web Site</td>\n<td width=\"330\">Creates a data-specific website that relies on dynamic data access techniques using either Entity Framework (EF) or LINQ-to-SQL programming. The structure consists of a presentation layer, a data layer, data source mapping, and the data store.</td>\n</tr>\n<tr>\n<td width=\"128\">ASP.NET Empty Web Site</td>\n<td width=\"180\">New Web Site, ASP.NET Web Application (.NET Framework), ASP.NET Core Web Application (.NET Core), ASP.NET Core Web Application (.NET Framework)</td>\n<td width=\"330\">Creates an empty website that doesn&#8217;t include any files, but does include basic support.</td>\n</tr>\n<tr>\n<td width=\"128\">ASP.NET Web Forms Site</td>\n<td width=\"180\">New Web Site, ASP.NET Web Application (.NET Framework)</td>\n<td width=\"330\">Creates a basic website that includes standard forms that are ready to fill out and use.</td>\n</tr>\n<tr>\n<td width=\"128\">ASP.NET Web Site (Razor v3)</td>\n<td width=\"180\">New Web Site</td>\n<td width=\"330\">Creates a basic website that includes standard forms. The form language relies on the Razor language (CSHTML) which is based on C#. Essentially, this kind of project is designed to make you more efficient, but only if you&#8217;re willing to learn the Razor language.</td>\n</tr>\n<tr>\n<td width=\"128\">Azure API App</td>\n<td width=\"180\">ASP.NET Web Application (.NET Framework)</td>\n<td width=\"330\">Constructs a cloud-based application environment that allows public access of services using a Web API. You can publish your APIs so that others can access the code to create a variety of application types.</td>\n</tr>\n<tr>\n<td width=\"128\">MVC (Model-View-Controller)</td>\n<td width=\"180\">ASP.NET Web Application (.NET Framework)</td>\n<td width=\"330\">Creates a basic website based on the Model-View-Controller approach, in which the model encapsulates data, the view displays the data to the user, and the controller encapsulates business logic used to access the data. The goal is to create applications quickly and in a manner that is easy to update and works well with teams.</td>\n</tr>\n<tr>\n<td width=\"128\">Single Page Application</td>\n<td width=\"180\">ASP.NET Web Application (.NET Framework)</td>\n<td width=\"330\">Constructs an application environment that is meant to interact with a Web API using a combination of HTML5, CSS3, and JavaScript. The single page represents a starting point that you can use to develop a much larger application.</td>\n</tr>\n<tr>\n<td width=\"128\">WCF Service</td>\n<td width=\"180\">New Web Site</td>\n<td width=\"330\">Defines a method for accessing services using the Windows Communication Foundation (WCF) framework rather than a more standard Web API. An oversimplification of the differences from the end user (developer access) perspective is that WCF relies on SOAP-based services, while a Web API generally relies on RESTful services.</td>\n</tr>\n<tr>\n<td width=\"128\">Web API</td>\n<td width=\"180\">ASP.NET Web Application (.NET Framework), ASP.NET Core Web Application (.NET Core), ASP.NET Core Web Application (.NET Framework)</td>\n<td width=\"330\">Defines a method for accessing services using a Web API rather than WCF. This project type represents the direction that modern applications are taking to simplify code access using RESTful techniques.</td>\n</tr>\n<tr>\n<td width=\"128\">Web Application</td>\n<td width=\"180\">ASP.NET Core Web Application (.NET Core), ASP.NET Core Web Application (.NET Framework)</td>\n<td width=\"330\">Creates a basic website that relies on the ASP.NET Core approach rather than the full functionality of the .NET Framework. This application can use the MVC methodology to development and includes support for Web API projects (using the RESTful programming technique).</td>\n</tr>\n</tbody>\n</table>\n"},{"title":"Common visual studio 2017 keyboard shortcuts","thumb":null,"image":null,"content":"<p>Touch typists find that using keyboard shortcuts makes them even faster than normal. Of course, you need to know the keyboard shortcuts before you can use them. The following table contains the keyboard shortcuts used most often in Visual Studio 2017. You can find a complete list of keyboard shortcuts <a href=\"https://docs.microsoft.com/en-us/visualstudio/ide/default-keyboard-shortcuts-in-visual-studio\" target=\"_blank\" rel=\"noopener\">online</a>.</p>\n<table>\n<tbody>\n<tr>\n<td width=\"152\"><strong>Shortcut</strong></td>\n<td width=\"513\"><strong>Purpose</strong></td>\n</tr>\n<tr>\n<td width=\"152\">Alt-Enter</td>\n<td width=\"513\">Show the properties panel for a selected object</td>\n</tr>\n<tr>\n<td width=\"152\">Alt-Shift-A</td>\n<td width=\"513\">Add an existing item to the project</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-Alt-L</td>\n<td width=\"513\">Show Solution Explorer</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-Alt-P</td>\n<td width=\"513\">Attach the debugger to a process</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-B + Ctrl-T</td>\n<td width=\"513\">Toggle code bookmark</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-F</td>\n<td width=\"513\">Display the Find dialog</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-F5</td>\n<td width=\"513\">Start a project without debugging</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-H</td>\n<td width=\"513\">Display the Replace dialog</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-K+Ctrl-C</td>\n<td width=\"513\">Comment a selected block of code</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-K+Ctrl-U</td>\n<td width=\"513\">Un-comment a selected block of code</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-M +Ctrl+M</td>\n<td width=\"513\">Expand or collapse a selected code fragment (toggle)</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-M +Ctrl-O</td>\n<td width=\"513\">Collapse all code to definitions</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-M +Ctrl-P</td>\n<td width=\"513\">Expand all definitions to code</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-N</td>\n<td width=\"513\">Add a new file</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-S</td>\n<td width=\"513\">Save file</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-Shift-A</td>\n<td width=\"513\">Add a new item to the project</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-Shift-B</td>\n<td width=\"513\">Build solution</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-Shift-Tab</td>\n<td width=\"513\">Scroll backwards through open windows</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-Tab</td>\n<td width=\"513\">Scroll forward through open windows</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-Y</td>\n<td width=\"513\">Redo typing</td>\n</tr>\n<tr>\n<td width=\"152\">Ctrl-Z</td>\n<td width=\"513\">Undo typing</td>\n</tr>\n<tr>\n<td width=\"152\">F5</td>\n<td width=\"513\">Start a project in debug mode</td>\n</tr>\n<tr>\n<td width=\"152\">F6</td>\n<td width=\"513\">Build solution</td>\n</tr>\n<tr>\n<td width=\"152\">F7</td>\n<td width=\"513\">Show the code window</td>\n</tr>\n<tr>\n<td width=\"152\">Shift-Alt-C</td>\n<td width=\"513\">Add a new class to the project</td>\n</tr>\n<tr>\n<td width=\"152\">Shift-F6</td>\n<td width=\"513\">Build project</td>\n</tr>\n<tr>\n<td width=\"152\">Shift-F7</td>\n<td width=\"513\">Show the designer window</td>\n</tr>\n</tbody>\n</table>\n"},{"title":"C# 7.0 keyword listing","thumb":null,"image":null,"content":"<p>All programming languages rely on <em>keywords, </em>which are words that are reserved and that you can&#8217;t use for your personal needs. Knowing the keywords enables you to choose other words for your code. For example, you can&#8217;t create a variable named <code>while </code>because it&#8217;s a C# keyword. The following table contains the C# keywords.</p>\n<table>\n<tbody>\n<tr>\n<td width=\"140\">abstract</td>\n<td width=\"134\">as</td>\n<td width=\"135\">base</td>\n<td width=\"139\">bool</td>\n<td width=\"117\">break</td>\n</tr>\n<tr>\n<td width=\"140\">byte</td>\n<td width=\"134\">case</td>\n<td width=\"135\">catch</td>\n<td width=\"139\">char</td>\n<td width=\"117\">checked</td>\n</tr>\n<tr>\n<td width=\"140\">class</td>\n<td width=\"134\">const</td>\n<td width=\"135\">continue</td>\n<td width=\"139\">decimal</td>\n<td width=\"117\">default</td>\n</tr>\n<tr>\n<td width=\"140\">delegate</td>\n<td width=\"134\">do</td>\n<td width=\"135\">double</td>\n<td width=\"139\">else</td>\n<td width=\"117\">enum</td>\n</tr>\n<tr>\n<td width=\"140\">event</td>\n<td width=\"134\">explicit</td>\n<td width=\"135\">extern</td>\n<td width=\"139\">false</td>\n<td width=\"117\">finally</td>\n</tr>\n<tr>\n<td width=\"140\">fixed</td>\n<td width=\"134\">float</td>\n<td width=\"135\">for</td>\n<td width=\"139\">foreach</td>\n<td width=\"117\">goto</td>\n</tr>\n<tr>\n<td width=\"140\">if</td>\n<td width=\"134\">implicit</td>\n<td width=\"135\">in</td>\n<td width=\"139\">int</td>\n<td width=\"117\">interface</td>\n</tr>\n<tr>\n<td width=\"140\">internal</td>\n<td width=\"134\">is</td>\n<td width=\"135\">lock</td>\n<td width=\"139\">long</td>\n<td width=\"117\">namespace</td>\n</tr>\n<tr>\n<td width=\"140\">new</td>\n<td width=\"134\">null</td>\n<td width=\"135\">object</td>\n<td width=\"139\">operator</td>\n<td width=\"117\">out</td>\n</tr>\n<tr>\n<td width=\"140\">override</td>\n<td width=\"134\">params</td>\n<td width=\"135\">private</td>\n<td width=\"139\">protected</td>\n<td width=\"117\">public</td>\n</tr>\n<tr>\n<td width=\"140\">readonly</td>\n<td width=\"134\">ref</td>\n<td width=\"135\">return</td>\n<td width=\"139\">sbyte</td>\n<td width=\"117\">sealed</td>\n</tr>\n<tr>\n<td width=\"140\">short</td>\n<td width=\"134\">sizeof</td>\n<td width=\"135\">stackalloc</td>\n<td width=\"139\">static</td>\n<td width=\"117\">string</td>\n</tr>\n<tr>\n<td width=\"140\">struct</td>\n<td width=\"134\">switch</td>\n<td width=\"135\">this</td>\n<td width=\"139\">throw</td>\n<td width=\"117\">true</td>\n</tr>\n<tr>\n<td width=\"140\">try</td>\n<td width=\"134\">typeof</td>\n<td width=\"135\">uint</td>\n<td width=\"139\">ulong</td>\n<td width=\"117\">unchecked</td>\n</tr>\n<tr>\n<td width=\"140\">unsafe</td>\n<td width=\"134\">ushort</td>\n<td width=\"135\">using</td>\n<td width=\"139\">using static</td>\n<td width=\"117\">virtual</td>\n</tr>\n<tr>\n<td width=\"140\">void</td>\n<td width=\"134\">volatile</td>\n<td width=\"135\">while</td>\n<td width=\"139\"></td>\n<td width=\"117\"></td>\n</tr>\n</tbody>\n</table>\n"}],"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"One year","lifeExpectancySetFrom":"2022-03-10T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":248715},{"headers":{"creationTime":"2021-12-08T22:01:54+00:00","modifiedTime":"2021-12-08T22:01:54+00:00","timestamp":"2022-09-14T18:18:52+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"C#","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"},"slug":"csharp","categoryId":33596}],"title":"C# 10.0 All-in-One For Dummies Cheat Sheet","strippedTitle":"c# 10.0 all-in-one for dummies cheat sheet","slug":"c-10-0-all-in-one-for-dummies-cheat-sheet","canonicalUrl":"","seo":{"metaDescription":"C# provides you with access to a phenomenal array of programming options. Use this cheat sheet to help you get the job done faster and easier when using C# as y","noIndex":0,"noFollow":0},"content":"C# provides you with access to a phenomenal array of programming options. Use this cheat sheet to help you get the job done faster and easier when using C# as your development solution of choice.","description":"C# provides you with access to a phenomenal array of programming options. Use this cheat sheet to help you get the job done faster and easier when using C# as your development solution of choice.","blurb":"","authors":[{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}}],"primaryCategoryTaxonomy":{"categoryId":33596,"title":"C#","slug":"csharp","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[],"fromCategory":[{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}},{"articleId":249449,"title":"Using Anonymous Methods in C#","slug":"using-anonymous-methods-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249449"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":289764,"slug":"c-10-0-all-in-one-for-dummies","isbn":"9781119839071","categoryList":["technology","programming-web-design","csharp"],"amazon":{"default":"https://www.amazon.com/gp/product/1119839076/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119839076/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119839076-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119839076/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119839076/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/9781119839071-203x255.jpg","width":203,"height":255},"title":"C# 10.0 All-in-One For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques.</p>","authors":[{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119839071&quot;]}]\" id=\"du-slot-63221b0c2c44e\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119839071&quot;]}]\" id=\"du-slot-63221b0c2cce3\"></div></div>"},"articleType":{"articleType":"Cheat Sheet","articleList":[{"articleId":0,"title":"","slug":null,"categoryList":[],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/"}}],"content":[{"title":"A quick overview of C# 10.0 desktop application templates","thumb":null,"image":null,"content":"<p>One of the areas where Microsoft has made big changes in C# 10.0 is in the ability to run applications just about anywhere given the proper pre-requisites. Consequently, it’s important for a developer to know which templates are available and which platforms they support.</p>\n<p>The following table makes it easier for you to find a particular template for desktop development. Note that this list assumes that you’re working with C# and not some of the other languages that Visual Studio 2022 supports.</p>\n<table>\n<tbody>\n<tr>\n<td width=\"127\"><strong>Project Type</strong></td>\n<td width=\"120\"><strong>Supported Environments</strong></td>\n<td width=\"285\"><strong>Description</strong></td>\n</tr>\n<tr>\n<td width=\"127\">Blank App (Universal Windows)</td>\n<td width=\"120\">Windows, Xbox, UWP, Desktop</td>\n<td width=\"285\">Allows creation of applications using the new Universal Windows Platform (UWP) approach. The template doesn’t provide any underlying application files.</td>\n</tr>\n<tr>\n<td width=\"127\">Empty Project (.NET Framework)</td>\n<td width=\"120\">Windows, Desktop</td>\n<td width=\"285\">Allows creation of Windows Forms applications. The template doesn’t provide any underlying application files. Note that this template uses older versions of the .NET Framework.</td>\n</tr>\n<tr>\n<td width=\"127\">NUnit Test Project</td>\n<td width=\"120\">Linux, macOS, Windows, Desktop, Web</td>\n<td width=\"285\">Provides the means to test your applications no matter where they might reside. The same testing process works on both the Web and on the Desktop.</td>\n</tr>\n<tr>\n<td width=\"127\">Shared Project</td>\n<td width=\"120\">Windows, Desktop</td>\n<td width=\"285\">Allows the creation of code that spans multiple projects. The goal is to allow building of the code differently based on the project in which it resides. You can learn more about this template type at <a href=\"https://docs.microsoft.com/visualstudio/extensibility/migration/update-visual-studio-extension\" target=\"_blank\" rel=\"noopener\">https://docs.microsoft.com/visualstudio/extensibility/migration/update-visual-studio-extension</a>.</td>\n</tr>\n<tr>\n<td width=\"127\">Windows Application Packaging Project</td>\n<td width=\"120\">Windows, UWP, Desktop</td>\n<td width=\"285\">Creates an application package that is contained in a <span style=\"text-decoration: line-through;\">.msix</span> file. The goal of this project is to create an application you can distribute through the Microsoft Store.</td>\n</tr>\n<tr>\n<td width=\"127\">Windows Forms App</td>\n<td width=\"120\">Windows, Desktop</td>\n<td width=\"285\">Creates a traditional Windows Forms application for use in the desktop environment. This template lets you use the newer .NET Framework 5.0 and above features.</td>\n</tr>\n<tr>\n<td width=\"127\">Windows Forms App (.NET Framework)</td>\n<td width=\"120\">Windows, Desktop</td>\n<td width=\"285\">Creates a traditional Windows Forms application for use in the desktop environment. Note that this project uses older versions of the .NET Framework.</td>\n</tr>\n<tr>\n<td width=\"127\">Windows Forms Class Library</td>\n<td width=\"120\">Windows, Desktop, Library</td>\n<td width=\"285\">Allows development of reusable code modules for Windows Forms applications.</td>\n</tr>\n<tr>\n<td width=\"127\">Windows Forms Control Library</td>\n<td width=\"120\">Windows, Desktop, Library</td>\n<td width=\"285\">Makes it possible to create custom or user controls for use in Windows Forms applications. This template lets you use the newer .NET Framework 5.0 and above features.</td>\n</tr>\n<tr>\n<td width=\"127\">Windows Forms Control Library (.NET Framework)</td>\n<td width=\"120\">Windows, Desktop, Library</td>\n<td width=\"285\">Makes it possible to create custom or user controls for use in Windows Forms applications. Note that this template uses older versions of the .NET Framework.</td>\n</tr>\n<tr>\n<td width=\"127\">Windows Service (.NET Framework)</td>\n<td width=\"120\">Windows, Desktop, Service</td>\n<td width=\"285\">Provides the means for creating an application that runs in the background as a service. Service setups are accessed through the Services MMC, rather than directly through a user interface. Note that this template uses older versions of the .NET Framework.</td>\n</tr>\n<tr>\n<td width=\"127\">WPF App (.NET Framework)</td>\n<td width=\"120\">Windows, Desktop</td>\n<td width=\"285\">Uses the newer Windows Presentation Foundation (WPF) approach to creating applications. Note that this template uses older versions of the .NET Framework.</td>\n</tr>\n<tr>\n<td width=\"127\">WPF Application</td>\n<td width=\"120\">Windows, Desktop</td>\n<td width=\"285\">Uses the newer Windows Presentation Foundation (WPF) approach to creating applications. This template lets you use the newer .NET Framework 5.0 and above features.</td>\n</tr>\n<tr>\n<td width=\"127\">WPF Browser App (.NET Framework)</td>\n<td width=\"120\">Windows, Desktop</td>\n<td width=\"285\">Allows creation of a browser-like application for the desktop using the WPF approach. Note that this template uses older versions of the .NET Framework.</td>\n</tr>\n<tr>\n<td width=\"127\">WPF Class Library</td>\n<td width=\"120\">Windows, Desktop, Library</td>\n<td width=\"285\">Allows development of reusable code modules for WPF applications.</td>\n</tr>\n<tr>\n<td width=\"127\">WPF Custom Control Library</td>\n<td width=\"120\">Widows, Desktop, Library</td>\n<td width=\"285\">Makes it possible to create custom controls for use in a WPF application. This template lets you use the newer .NET Framework 5.0 and above features.</td>\n</tr>\n<tr>\n<td width=\"127\">WPF Custom Control Library (.NET Framework)</td>\n<td width=\"120\">Windows, Desktop, Library</td>\n<td width=\"285\">Makes it possible to create custom controls for use in a WPF application. Note that this template uses older versions of the .NET Framework.</td>\n</tr>\n<tr>\n<td width=\"127\">WPF User Control Library</td>\n<td width=\"120\">Windows, Desktop, Library</td>\n<td width=\"285\">Makes it possible to create user controls for use in a WPF application. This template lets you use the newer .NET Framework 5.0 and above features.</td>\n</tr>\n<tr>\n<td width=\"127\">WPF User Control Library (.NET Framework)</td>\n<td width=\"120\">Windows, Desktop, Library</td>\n<td width=\"285\">Makes it possible to create user controls for use in a WPF application. Note that this template uses older versions of the .NET Framework.</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n"},{"title":"C# 10.0 keyword listing","thumb":null,"image":null,"content":"<p>All programming languages rely on <em>keywords </em>— words that are reserved and that you can’t use for your personal needs. Knowing the keywords makes it possible for you to choose other words for your code. For example, you couldn’t create a variable named &#8220;while&#8221; because it’s a C# keyword. The following table contains the C# keywords.</p>\n<table>\n<tbody>\n<tr>\n<td width=\"112\">abstract</td>\n<td width=\"107\">as</td>\n<td width=\"108\">base</td>\n<td width=\"111\">bool</td>\n<td width=\"93\">break</td>\n</tr>\n<tr>\n<td width=\"112\">Byte</td>\n<td width=\"107\">case</td>\n<td width=\"108\">catch</td>\n<td width=\"111\">char</td>\n<td width=\"93\">checked</td>\n</tr>\n<tr>\n<td width=\"112\">class</td>\n<td width=\"107\">const</td>\n<td width=\"108\">continue</td>\n<td width=\"111\">decimal</td>\n<td width=\"93\">default</td>\n</tr>\n<tr>\n<td width=\"112\">delegate</td>\n<td width=\"107\">do</td>\n<td width=\"108\">double</td>\n<td width=\"111\">else</td>\n<td width=\"93\">enum</td>\n</tr>\n<tr>\n<td width=\"112\">event</td>\n<td width=\"107\">explicit</td>\n<td width=\"108\">extern</td>\n<td width=\"111\">false</td>\n<td width=\"93\">finally</td>\n</tr>\n<tr>\n<td width=\"112\">fixed</td>\n<td width=\"107\">float</td>\n<td width=\"108\">for</td>\n<td width=\"111\">foreach</td>\n<td width=\"93\">goto</td>\n</tr>\n<tr>\n<td width=\"112\">if</td>\n<td width=\"107\">implicit</td>\n<td width=\"108\">in</td>\n<td width=\"111\">int</td>\n<td width=\"93\">interface</td>\n</tr>\n<tr>\n<td width=\"112\">internal</td>\n<td width=\"107\">is</td>\n<td width=\"108\">lock</td>\n<td width=\"111\">long</td>\n<td width=\"93\">namespace</td>\n</tr>\n<tr>\n<td width=\"112\">new</td>\n<td width=\"107\">null</td>\n<td width=\"108\">object</td>\n<td width=\"111\">operator</td>\n<td width=\"93\">out</td>\n</tr>\n<tr>\n<td width=\"112\">override</td>\n<td width=\"107\">params</td>\n<td width=\"108\">private</td>\n<td width=\"111\">protected</td>\n<td width=\"93\">public</td>\n</tr>\n<tr>\n<td width=\"112\">readonly</td>\n<td width=\"107\">ref</td>\n<td width=\"108\">return</td>\n<td width=\"111\">sbyte</td>\n<td width=\"93\">sealed</td>\n</tr>\n<tr>\n<td width=\"112\">short</td>\n<td width=\"107\">sizeof</td>\n<td width=\"108\">stackalloc</td>\n<td width=\"111\">static</td>\n<td width=\"93\">string</td>\n</tr>\n<tr>\n<td width=\"112\">struct</td>\n<td width=\"107\">switch</td>\n<td width=\"108\">this</td>\n<td width=\"111\">throw</td>\n<td width=\"93\">true</td>\n</tr>\n<tr>\n<td width=\"112\">try</td>\n<td width=\"107\">typeof</td>\n<td width=\"108\">uint</td>\n<td width=\"111\">ulong</td>\n<td width=\"93\">unchecked</td>\n</tr>\n<tr>\n<td width=\"112\">unsafe</td>\n<td width=\"107\">ushort</td>\n<td width=\"108\">using</td>\n<td width=\"111\">virtual</td>\n<td width=\"93\">void</td>\n</tr>\n<tr>\n<td width=\"112\">volatile</td>\n<td width=\"107\">while</td>\n<td width=\"108\">&nbsp;</td>\n<td width=\"111\">&nbsp;</td>\n<td width=\"93\">&nbsp;</td>\n</tr>\n</tbody>\n</table>\n"},{"title":"Common Visual Studio 2022 keyboard shortcuts","thumb":null,"image":null,"content":"<p>Touch typists find that using keyboard shortcuts makes them even faster than normal. Of course, you need to know the keyboard shortcuts before you can use them. The following table contains the keyboard shortcuts used most often in Visual Studio 2022. You can find a complete list of keyboard shortcuts at <a href=\"https://docs.microsoft.com/visualstudio/ide/default-keyboard-shortcuts-in-visual-studio\" target=\"_blank\" rel=\"noopener\">https://docs.microsoft.com/visualstudio/ide/default-keyboard-shortcuts-in-visual-studio</a>.</p>\n<table>\n<tbody>\n<tr>\n<td width=\"121\"><strong>Shortcut</strong></td>\n<td width=\"411\"><strong>Purpose</strong></td>\n</tr>\n<tr>\n<td width=\"121\">Alt+Enter</td>\n<td width=\"411\">Show the properties panel for a selected object</td>\n</tr>\n<tr>\n<td width=\"121\">Alt+Shift+A</td>\n<td width=\"411\">Add an existing item to the project</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+Alt+L</td>\n<td width=\"411\">Show Solution Explorer</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+Alt+P</td>\n<td width=\"411\">Attach the debugger to a process</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+B, Ctrl+T</td>\n<td width=\"411\">Toggle code bookmark</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+F</td>\n<td width=\"411\">Display the Find dialog</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+F5</td>\n<td width=\"411\">Start a project without debugging</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+H</td>\n<td width=\"411\">Display the Replace dialog</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+K, Ctrl+C</td>\n<td width=\"411\">Comment a selected block of code</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+K, Ctrl+U</td>\n<td width=\"411\">Un-comment a selected block of code</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+M, Ctrl+M</td>\n<td width=\"411\">Expand or collapse a selected code fragment (toggle)</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+M, Ctrl+O</td>\n<td width=\"411\">Collapse all code to definitions</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+M, Ctrl+P</td>\n<td width=\"411\">Expand all definitions to code</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+N</td>\n<td width=\"411\">Add a new file</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+S</td>\n<td width=\"411\">Save file</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+Shift+A</td>\n<td width=\"411\">Add a new item to the project</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+Shift+B</td>\n<td width=\"411\">Build solution</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+Shift+N</td>\n<td width=\"411\">Close the current project and start a new project</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+Shift+O</td>\n<td width=\"411\">Close the current project and open an existing project</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+Shift+F10</td>\n<td width=\"411\">During debugging, set execution to the line holding the cursor</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+Shift+Tab</td>\n<td width=\"411\">Scroll backwards through open windows</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+Tab</td>\n<td width=\"411\">Scroll forward through open windows</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+Y</td>\n<td width=\"411\">Redo typing</td>\n</tr>\n<tr>\n<td width=\"121\">Ctrl+Z</td>\n<td width=\"411\">Undo typing</td>\n</tr>\n<tr>\n<td width=\"121\">F5</td>\n<td width=\"411\">Start a project in debug mode</td>\n</tr>\n<tr>\n<td width=\"121\">F6</td>\n<td width=\"411\">Build solution</td>\n</tr>\n<tr>\n<td width=\"121\">F7</td>\n<td width=\"411\">Show the code window</td>\n</tr>\n<tr>\n<td width=\"121\">F9</td>\n<td width=\"411\">During debugging, toggle breakpoint on the line holding the cursor</td>\n</tr>\n<tr>\n<td width=\"121\">F12</td>\n<td width=\"411\">In the code editor, jump to the selected object’s definition</td>\n</tr>\n<tr>\n<td width=\"121\">Shift+Alt+C</td>\n<td width=\"411\">Add a new class to the project</td>\n</tr>\n<tr>\n<td width=\"121\">Shift+F6</td>\n<td width=\"411\">Build project</td>\n</tr>\n<tr>\n<td width=\"121\">Shift+F7</td>\n<td width=\"411\">Show the designer window</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;</p>\n"}],"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"One year","lifeExpectancySetFrom":"2021-12-08T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":289765},{"headers":{"creationTime":"2018-02-01T13:00:26+00:00","modifiedTime":"2018-02-01T13:00:26+00:00","timestamp":"2022-09-14T18:16:13+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"C#","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"},"slug":"csharp","categoryId":33596}],"title":"Making Sure Your ASP.NET Site Is Accessible","strippedTitle":"making sure your asp.net site is accessible","slug":"making-sure-asp-net-site-accessible","canonicalUrl":"","seo":{"metaDescription":"Everyone has special needs, and those needs change as time progresses. Microsoft is aware of this. Someone with perfect eyesight in the morning might suffer fro","noIndex":0,"noFollow":0},"content":"Everyone has special needs, and those needs change as time progresses. Microsoft is aware of this. Someone with perfect eyesight in the morning might suffer from tired eyes in the afternoon. Many web users have some sort of special need all the time. Whether the need is intermittent or constant, making your site <em>accessible</em> means making it easy for everyone to use.\r\n\r\nMicrosoft has made a significant investment in accessible web browsing, and you’ll be pleased to find that most of the controls make good decisions about accessibility right out of the box. Understanding how to use them for this purpose takes a little effort, however.\r\n<p class=\"article-tips tip\">If you’re building websites for large enterprises or the government, <a href=\"http://www.section508.gov/\">Section 508</a> (an amendment to the Rehabilitation Act) makes this very important. Check out Accessibility for Everybody, by John Paul Mueller (Apress) for more information.</p>\r\nMost ASP.NET controls, where applicable, fit a certain feature list for accessibility. The goal is to make coding for accessibility easy for the programmer and functional for the user.\r\n<ul>\r\n \t<li>Any element that isn’t made of text should have an alternate text option. For instance, all image tags support an <code>AlternateText</code> property, which populates the HTML <code>alt</code> tag. web-to-text readers will “speak” the contents of this tag in place of the image. If you add an image to a web page, Visual Studio even prompts you for the alternate text.</li>\r\n \t<li>Controls don’t require the use of style sheets or color dependency. If you want, you can easily strip all style information from a page for simplicity of use by a reader or a low-sight version of the application.</li>\r\n \t<li>All input controls in Getting Input from the User support a <code>TabIndex</code> property, which allows users to tab from control to control. For those not using a mouse, this is optimum.</li>\r\n \t<li>Setting which part of the form has the cursor by default (called <em>default focus</em>) is easy in ASP.NET with the <code>DefaultFocus</code> property. Changing it is easy with the <code>SetFocus</code> method.</li>\r\n \t<li>You can give buttons keyboard equivalents by using the <code>AccessKey</code> property.</li>\r\n \t<li>Labels and input controls can be associated, which many web readers depend on.</li>\r\n</ul>\r\nA feature in Visual Studio called Check Page for Accessibility checks web Content Accessibility Guidelines (WCAG) and Section 508 errors. If you use this feature, warnings will actually be posted to your build process.","description":"Everyone has special needs, and those needs change as time progresses. Microsoft is aware of this. Someone with perfect eyesight in the morning might suffer from tired eyes in the afternoon. Many web users have some sort of special need all the time. Whether the need is intermittent or constant, making your site <em>accessible</em> means making it easy for everyone to use.\r\n\r\nMicrosoft has made a significant investment in accessible web browsing, and you’ll be pleased to find that most of the controls make good decisions about accessibility right out of the box. Understanding how to use them for this purpose takes a little effort, however.\r\n<p class=\"article-tips tip\">If you’re building websites for large enterprises or the government, <a href=\"http://www.section508.gov/\">Section 508</a> (an amendment to the Rehabilitation Act) makes this very important. Check out Accessibility for Everybody, by John Paul Mueller (Apress) for more information.</p>\r\nMost ASP.NET controls, where applicable, fit a certain feature list for accessibility. The goal is to make coding for accessibility easy for the programmer and functional for the user.\r\n<ul>\r\n \t<li>Any element that isn’t made of text should have an alternate text option. For instance, all image tags support an <code>AlternateText</code> property, which populates the HTML <code>alt</code> tag. web-to-text readers will “speak” the contents of this tag in place of the image. If you add an image to a web page, Visual Studio even prompts you for the alternate text.</li>\r\n \t<li>Controls don’t require the use of style sheets or color dependency. If you want, you can easily strip all style information from a page for simplicity of use by a reader or a low-sight version of the application.</li>\r\n \t<li>All input controls in Getting Input from the User support a <code>TabIndex</code> property, which allows users to tab from control to control. For those not using a mouse, this is optimum.</li>\r\n \t<li>Setting which part of the form has the cursor by default (called <em>default focus</em>) is easy in ASP.NET with the <code>DefaultFocus</code> property. Changing it is easy with the <code>SetFocus</code> method.</li>\r\n \t<li>You can give buttons keyboard equivalents by using the <code>AccessKey</code> property.</li>\r\n \t<li>Labels and input controls can be associated, which many web readers depend on.</li>\r\n</ul>\r\nA feature in Visual Studio called Check Page for Accessibility checks web Content Accessibility Guidelines (WCAG) and Section 508 errors. If you use this feature, warnings will actually be posted to your build process.","blurb":"","authors":[{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}},{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}}],"primaryCategoryTaxonomy":{"categoryId":33596,"title":"C#","slug":"csharp","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}},{"articleId":249449,"title":"Using Anonymous Methods in C#","slug":"using-anonymous-methods-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249449"}},{"articleId":249446,"title":"How to Seal a C# Class","slug":"seal-c-class","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249446"}}],"fromCategory":[{"articleId":289765,"title":"C# 10.0 All-in-One For Dummies Cheat Sheet","slug":"c-10-0-all-in-one-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/289765"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}},{"articleId":249449,"title":"Using Anonymous Methods in C#","slug":"using-anonymous-methods-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249449"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281649,"slug":"c-7-0-all-in-one-for-dummies","isbn":"9781119428114","categoryList":["technology","programming-web-design","csharp"],"amazon":{"default":"https://www.amazon.com/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119428114-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/c-sharp-7.0-all-in-one-for-dummies-cover-9781119428114-203x255.jpg","width":203,"height":255},"title":"C# 7.0 All-in-One For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9109\">John Paul Mueller</b> is a writer on programming topics like AWS, Python, Java, HTML, CSS, and JavaScript. <b data-author-id=\"9786\">William Sempf</b> is a programmer and .NET evangelist. <b data-author-id=\"9787\">Chuck Sphar</b> was a full-time senior technical writer for the Visual C++ product group at Microsoft. </p>","authors":[{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}},{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6da927d\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6da9d1a\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":null,"lifeExpectancySetFrom":null,"dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":249507},{"headers":{"creationTime":"2018-02-01T12:30:37+00:00","modifiedTime":"2018-02-01T12:30:37+00:00","timestamp":"2022-09-14T18:16:13+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"C#","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"},"slug":"csharp","categoryId":33596}],"title":"Employing Dynamic C# Programming Techniques","strippedTitle":"employing dynamic c# programming techniques","slug":"employing-dynamic-c-programming-techniques","canonicalUrl":"","seo":{"metaDescription":"When you define a new variable, you can use the dynamic keyword, and C# will let you make assumptions about the members of the variable. For example, if you wan","noIndex":0,"noFollow":0},"content":"When you define a new variable, you can use the <code>dynamic</code> keyword, and C# will let you make assumptions about the members of the variable. For example, if you want to declare a new <code>Course</code> object, you do it like this:\r\n\r\n<code>Course newCourse = new Course();</code>\r\n\r\n<code>newCourse.Schedule();</code>\r\n\r\nThis is, of course, assuming that you have a <code>Course</code> class defined somewhere else in your program, like this:\r\n\r\n<code>class Course {</code>\r\n\r\n<code>public void Schedule()</code>\r\n\r\n<code>{</code>\r\n\r\n<code>//Something fancy here</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nBut what if you don't know what class the new object will be? How do you handle that? You could declare it as an <code>Object</code>, because everything derives from <code>Object</code>, right? Here's the code:\r\n\r\n<code>Object newCourse = new Object();</code>\r\n\r\nNot so fast, if you make your next line this:\r\n\r\n<code>newCourse.Schedule();</code>\r\n\r\nNote the squiggly line appears almost immediately, and you get the famous “object does not contain a definition for Schedule…” error in the design time Error List. However, you can do this:\r\n\r\n<code>dynamic newCourse = SomeFunction();</code>\r\n\r\n<code>newCourse.Schedule();</code>\r\n\r\nAll this code needs to have is the stub of a function that returns some value, and you are good to go. What if <code>SomeFunction()</code> returns a string? Well, you get a runtime error. But it will still compile!\r\n\r\nAbout now you may be thinking: “This is a <em>good</em> thing? How!?!” For the time being, you can blame COM. You see, COM was mostly constructed using C++, which has a variant type. In C++, you could declare a variable to be dynamic, like this:\r\n\r\n<code>VARIANT newCourse;</code>\r\n\r\nIt worked just like the dynamic type, except C# wasn't invented yet. Anyway, because a lot of the objects in COM used <code>VARIANT</code> out parameters, it was really tough to handle Interop using .NET. Because Microsoft Office is mostly made of COM objects, and because it isn't going to change any time soon, and because Microsoft all C# programmers to be Office developers one day, bam, you have the dynamic type.\r\n\r\nSay, for instance, that your <code>newCourse</code> is a variant out parameter from a method in a COM class. To get the value, you have to declare it an Object, like this:\r\n\r\n<code>CourseMarshaller cm = new CourseMarshaller(); //a COM object</code>\r\n\r\n<code>int courseId = 4;</code>\r\n\r\n<code>Object newCourse;</code>\r\n\r\n<code>cm.MakeCourse(courseId, newCourse);</code>\r\n\r\n<code>//and now we are back to square one</code>\r\n\r\n<code>newCourse.Schedule(); //This causes a 'member not found exception'</code>\r\n\r\nLine 6 will not compile, even if the Schedule method exists, because you can't assume that <code>newCourse</code> will always come back as a Course object, because it is declared a variant. You’re stuck. With a dynamic type, though, you’re golden once again, with this code:\r\n\r\n<code>CourseMarshaller cm = new CourseMarshaller(); //a COM object</code>\r\n\r\n<code>int courseId = 4;</code>\r\n\r\n<code>dynamic newCourse;</code>\r\n\r\n<code>cm.MakeCourse(courseId, newCourse);</code>\r\n\r\n<code>newCourse.Schedule(); //This now compiles</code>\r\n\r\nWhat happens if <code>newCourse</code> comes back as something that doesn't have a Schedule method? You get a runtime error. But there are <code>try/catch</code> blocks for runtime errors. Nothing will help it compile without the <code>dynamic</code> keyword.\r\n\r\nReaders who are long-time Visual Basic programmers, or even newer VB.NET programmers, realize that you can handle this dynamically — and have always been able to — in Visual Basic. Some developers recommend that programmers who work with legacy systems use Visual Basic for their new code, and this is exactly why.\r\n\r\nIn the interest of language parity, now C# can do it, too. In general, this is good, because many organizations are writing legacy code in VB and new code in C# — and it can get pretty messy in the trenches. This change makes the code base slimmer.","description":"When you define a new variable, you can use the <code>dynamic</code> keyword, and C# will let you make assumptions about the members of the variable. For example, if you want to declare a new <code>Course</code> object, you do it like this:\r\n\r\n<code>Course newCourse = new Course();</code>\r\n\r\n<code>newCourse.Schedule();</code>\r\n\r\nThis is, of course, assuming that you have a <code>Course</code> class defined somewhere else in your program, like this:\r\n\r\n<code>class Course {</code>\r\n\r\n<code>public void Schedule()</code>\r\n\r\n<code>{</code>\r\n\r\n<code>//Something fancy here</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nBut what if you don't know what class the new object will be? How do you handle that? You could declare it as an <code>Object</code>, because everything derives from <code>Object</code>, right? Here's the code:\r\n\r\n<code>Object newCourse = new Object();</code>\r\n\r\nNot so fast, if you make your next line this:\r\n\r\n<code>newCourse.Schedule();</code>\r\n\r\nNote the squiggly line appears almost immediately, and you get the famous “object does not contain a definition for Schedule…” error in the design time Error List. However, you can do this:\r\n\r\n<code>dynamic newCourse = SomeFunction();</code>\r\n\r\n<code>newCourse.Schedule();</code>\r\n\r\nAll this code needs to have is the stub of a function that returns some value, and you are good to go. What if <code>SomeFunction()</code> returns a string? Well, you get a runtime error. But it will still compile!\r\n\r\nAbout now you may be thinking: “This is a <em>good</em> thing? How!?!” For the time being, you can blame COM. You see, COM was mostly constructed using C++, which has a variant type. In C++, you could declare a variable to be dynamic, like this:\r\n\r\n<code>VARIANT newCourse;</code>\r\n\r\nIt worked just like the dynamic type, except C# wasn't invented yet. Anyway, because a lot of the objects in COM used <code>VARIANT</code> out parameters, it was really tough to handle Interop using .NET. Because Microsoft Office is mostly made of COM objects, and because it isn't going to change any time soon, and because Microsoft all C# programmers to be Office developers one day, bam, you have the dynamic type.\r\n\r\nSay, for instance, that your <code>newCourse</code> is a variant out parameter from a method in a COM class. To get the value, you have to declare it an Object, like this:\r\n\r\n<code>CourseMarshaller cm = new CourseMarshaller(); //a COM object</code>\r\n\r\n<code>int courseId = 4;</code>\r\n\r\n<code>Object newCourse;</code>\r\n\r\n<code>cm.MakeCourse(courseId, newCourse);</code>\r\n\r\n<code>//and now we are back to square one</code>\r\n\r\n<code>newCourse.Schedule(); //This causes a 'member not found exception'</code>\r\n\r\nLine 6 will not compile, even if the Schedule method exists, because you can't assume that <code>newCourse</code> will always come back as a Course object, because it is declared a variant. You’re stuck. With a dynamic type, though, you’re golden once again, with this code:\r\n\r\n<code>CourseMarshaller cm = new CourseMarshaller(); //a COM object</code>\r\n\r\n<code>int courseId = 4;</code>\r\n\r\n<code>dynamic newCourse;</code>\r\n\r\n<code>cm.MakeCourse(courseId, newCourse);</code>\r\n\r\n<code>newCourse.Schedule(); //This now compiles</code>\r\n\r\nWhat happens if <code>newCourse</code> comes back as something that doesn't have a Schedule method? You get a runtime error. But there are <code>try/catch</code> blocks for runtime errors. Nothing will help it compile without the <code>dynamic</code> keyword.\r\n\r\nReaders who are long-time Visual Basic programmers, or even newer VB.NET programmers, realize that you can handle this dynamically — and have always been able to — in Visual Basic. Some developers recommend that programmers who work with legacy systems use Visual Basic for their new code, and this is exactly why.\r\n\r\nIn the interest of language parity, now C# can do it, too. In general, this is good, because many organizations are writing legacy code in VB and new code in C# — and it can get pretty messy in the trenches. This change makes the code base slimmer.","blurb":"","authors":[{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}},{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}}],"primaryCategoryTaxonomy":{"categoryId":33596,"title":"C#","slug":"csharp","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}},{"articleId":249449,"title":"Using Anonymous Methods in C#","slug":"using-anonymous-methods-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249449"}},{"articleId":249446,"title":"How to Seal a C# Class","slug":"seal-c-class","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249446"}}],"fromCategory":[{"articleId":289765,"title":"C# 10.0 All-in-One For Dummies Cheat Sheet","slug":"c-10-0-all-in-one-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/289765"}},{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}},{"articleId":249449,"title":"Using Anonymous Methods in C#","slug":"using-anonymous-methods-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249449"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281649,"slug":"c-7-0-all-in-one-for-dummies","isbn":"9781119428114","categoryList":["technology","programming-web-design","csharp"],"amazon":{"default":"https://www.amazon.com/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119428114-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/c-sharp-7.0-all-in-one-for-dummies-cover-9781119428114-203x255.jpg","width":203,"height":255},"title":"C# 7.0 All-in-One For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9109\">John Paul Mueller</b> is a writer on programming topics like AWS, Python, Java, HTML, CSS, and JavaScript. <b data-author-id=\"9786\">William Sempf</b> is a programmer and .NET evangelist. <b data-author-id=\"9787\">Chuck Sphar</b> was a full-time senior technical writer for the Visual C++ product group at Microsoft. </p>","authors":[{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}},{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6da198d\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6da223d\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":null,"lifeExpectancySetFrom":null,"dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":249504},{"headers":{"creationTime":"2018-01-31T12:55:17+00:00","modifiedTime":"2018-01-31T12:55:17+00:00","timestamp":"2022-09-14T18:16:13+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"C#","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"},"slug":"csharp","categoryId":33596}],"title":"Using Structures as Records in C#","strippedTitle":"using structures as records in c#","slug":"using-structures-records-c","canonicalUrl":"","seo":{"metaDescription":"The main reason to work with structures in most code is to create records that contain custom data. You use these custom data records to hold complex informatio","noIndex":0,"noFollow":0},"content":"The main reason to work with structures in most code is to create records that contain custom data. You use these custom data records to hold complex information and pass it around as needed within your application. It’s easier and faster to pass a single record than it is to pass a collection of data values, especially when your application performs the task regularly. Keep reading to find out how to use structures as a kind of data record.\r\n<h2 id=\"tab1\" >Managing a single record</h2>\r\nPassing structures to methods is cleaner and easier than passing a collection of individual data values. Of course, the values in the structure must be related in order for this strategy to work well. However, consider the following method:\r\n\r\n<code>static void DisplayMessage(Message msg)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>Console.WriteLine(</code>\r\n\r\n<code>\"In response to Msg {0}, you can get {1} of {2} for {3}.\",</code>\r\n\r\n<code>msg.MsgID, msg.Qty, msg.ProductID, msg.Price);</code>\r\n\r\n<code>}</code>\r\n<p class=\"article-tips tip\">In this case, the <code>DisplayMessage()</code> method receives a single input of type <code>Message</code> instead of the four variables that the method would normally require. Using the <code>Message</code> structure produces these positive results in the code:</p>\r\n\r\n<ul>\r\n \t<li>The receiving method can assume that all the required data values are present.</li>\r\n \t<li>The receiving method can assume that all the variables are initialized.</li>\r\n \t<li>The caller is less likely to create erroneous code.</li>\r\n \t<li>Other developers can read the code with greater ease.</li>\r\n \t<li>Code changes are easier to make.</li>\r\n</ul>\r\n<h2 id=\"tab2\" >Adding structures to arrays</h2>\r\nApplications rarely use a single data record for every purpose. In most cases, applications also include database-like collections of records. For example, an application is unlikely to receive just one <code>Message</code>. Instead, the application will likely receive a group of <code>Message</code> records, each of which it must process.\r\n<p class=\"article-tips tech\">You can add structures to any collection. However, most collections work with objects, so adding a structure to them would incur a performance penalty because C# must box and unbox each structure individually. As the size of the collection increases, the penalty becomes quite noticeable. Consequently, it’s always a better idea to restrict collections of data records that rely on structures to arrays in your application when speed is the most important concern.</p>\r\nWorking with an array of structures is much like working with an array of anything else. You could use code like this to create an array of Message structures:\r\n\r\n<code>// Display all the messages on screen.</code>\r\n\r\n<code>Message[] Msgs = { myMsg, myMsg2 };</code>\r\n\r\n<code>DisplayMessages(Msgs);</code>\r\n\r\nIn this case,<code> Msgs</code> contains two records, <code>myMsg</code> and <code>myMsg2</code>. The code then processes the messages by passing the array to <code>DisplayMessages()</code>, which is shown here:\r\n\r\n<code>static void DisplayMessages(Message[] msgs)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>foreach (Message item in msgs)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>Console.WriteLine(</code>\r\n\r\n<code>\"In response to Msg {0}, you can get {1} of {2} for {3}.\",</code>\r\n\r\n<code>item.MsgID, item.Qty, item.ProductID, item.Price);</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nThe <code>DisplayMessages()</code> method uses a <code>foreach</code> loop to separate the individual <code>Message</code> records. It then processes them using the same approach as <code>DisplayMessage()</code>.\r\n<h2 id=\"tab3\" >Overriding methods</h2>\r\nStructures provide a great deal of flexibility that many developers assign exclusively to classes. For example, you can override methods, often in ways that make the structure output infinitely better. A good example is the <code>ToString()</code> method, which outputs a somewhat unhelpful (or something similar):\r\n\r\n<code>Structures.Program+Messages</code>\r\n\r\nThe output isn’t useful because it doesn’t tell you anything. To garner anything useful, you must override the <code>ToString()</code> method by using code like this:\r\n\r\n<code>public override string ToString()</code>\r\n\r\n<code>{</code>\r\n\r\n<code>// Create a useful output string.</code>\r\n\r\n<code>return \"Message ID:\\t\" + MsgID +</code>\r\n\r\n<code>\"\\r\\nProduct ID:\\t\" + ProductID +</code>\r\n\r\n<code>\"\\r\\nQuantity:\\t\" + Qty +</code>\r\n\r\n<code>\"\\r\\nTotal Price:\\t\" + Price;</code>\r\n\r\n<code>}</code>\r\n\r\nNow when you call <code>ToString()</code>, you obtain useful information. In this case, you see the following output when calling <code>myMsg.ToString()</code>:\r\n\r\n<code>Message ID: 1</code>\r\n\r\n<code>Product ID: 22</code>\r\n\r\n<code>Quantity: 5</code>\r\n\r\n<code>Total Price: 29.95</code>","description":"The main reason to work with structures in most code is to create records that contain custom data. You use these custom data records to hold complex information and pass it around as needed within your application. It’s easier and faster to pass a single record than it is to pass a collection of data values, especially when your application performs the task regularly. Keep reading to find out how to use structures as a kind of data record.\r\n<h2 id=\"tab1\" >Managing a single record</h2>\r\nPassing structures to methods is cleaner and easier than passing a collection of individual data values. Of course, the values in the structure must be related in order for this strategy to work well. However, consider the following method:\r\n\r\n<code>static void DisplayMessage(Message msg)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>Console.WriteLine(</code>\r\n\r\n<code>\"In response to Msg {0}, you can get {1} of {2} for {3}.\",</code>\r\n\r\n<code>msg.MsgID, msg.Qty, msg.ProductID, msg.Price);</code>\r\n\r\n<code>}</code>\r\n<p class=\"article-tips tip\">In this case, the <code>DisplayMessage()</code> method receives a single input of type <code>Message</code> instead of the four variables that the method would normally require. Using the <code>Message</code> structure produces these positive results in the code:</p>\r\n\r\n<ul>\r\n \t<li>The receiving method can assume that all the required data values are present.</li>\r\n \t<li>The receiving method can assume that all the variables are initialized.</li>\r\n \t<li>The caller is less likely to create erroneous code.</li>\r\n \t<li>Other developers can read the code with greater ease.</li>\r\n \t<li>Code changes are easier to make.</li>\r\n</ul>\r\n<h2 id=\"tab2\" >Adding structures to arrays</h2>\r\nApplications rarely use a single data record for every purpose. In most cases, applications also include database-like collections of records. For example, an application is unlikely to receive just one <code>Message</code>. Instead, the application will likely receive a group of <code>Message</code> records, each of which it must process.\r\n<p class=\"article-tips tech\">You can add structures to any collection. However, most collections work with objects, so adding a structure to them would incur a performance penalty because C# must box and unbox each structure individually. As the size of the collection increases, the penalty becomes quite noticeable. Consequently, it’s always a better idea to restrict collections of data records that rely on structures to arrays in your application when speed is the most important concern.</p>\r\nWorking with an array of structures is much like working with an array of anything else. You could use code like this to create an array of Message structures:\r\n\r\n<code>// Display all the messages on screen.</code>\r\n\r\n<code>Message[] Msgs = { myMsg, myMsg2 };</code>\r\n\r\n<code>DisplayMessages(Msgs);</code>\r\n\r\nIn this case,<code> Msgs</code> contains two records, <code>myMsg</code> and <code>myMsg2</code>. The code then processes the messages by passing the array to <code>DisplayMessages()</code>, which is shown here:\r\n\r\n<code>static void DisplayMessages(Message[] msgs)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>foreach (Message item in msgs)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>Console.WriteLine(</code>\r\n\r\n<code>\"In response to Msg {0}, you can get {1} of {2} for {3}.\",</code>\r\n\r\n<code>item.MsgID, item.Qty, item.ProductID, item.Price);</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nThe <code>DisplayMessages()</code> method uses a <code>foreach</code> loop to separate the individual <code>Message</code> records. It then processes them using the same approach as <code>DisplayMessage()</code>.\r\n<h2 id=\"tab3\" >Overriding methods</h2>\r\nStructures provide a great deal of flexibility that many developers assign exclusively to classes. For example, you can override methods, often in ways that make the structure output infinitely better. A good example is the <code>ToString()</code> method, which outputs a somewhat unhelpful (or something similar):\r\n\r\n<code>Structures.Program+Messages</code>\r\n\r\nThe output isn’t useful because it doesn’t tell you anything. To garner anything useful, you must override the <code>ToString()</code> method by using code like this:\r\n\r\n<code>public override string ToString()</code>\r\n\r\n<code>{</code>\r\n\r\n<code>// Create a useful output string.</code>\r\n\r\n<code>return \"Message ID:\\t\" + MsgID +</code>\r\n\r\n<code>\"\\r\\nProduct ID:\\t\" + ProductID +</code>\r\n\r\n<code>\"\\r\\nQuantity:\\t\" + Qty +</code>\r\n\r\n<code>\"\\r\\nTotal Price:\\t\" + Price;</code>\r\n\r\n<code>}</code>\r\n\r\nNow when you call <code>ToString()</code>, you obtain useful information. In this case, you see the following output when calling <code>myMsg.ToString()</code>:\r\n\r\n<code>Message ID: 1</code>\r\n\r\n<code>Product ID: 22</code>\r\n\r\n<code>Quantity: 5</code>\r\n\r\n<code>Total Price: 29.95</code>","blurb":"","authors":[{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}},{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}}],"primaryCategoryTaxonomy":{"categoryId":33596,"title":"C#","slug":"csharp","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[{"label":"Managing a single record","target":"#tab1"},{"label":"Adding structures to arrays","target":"#tab2"},{"label":"Overriding methods","target":"#tab3"}],"relatedArticles":{"fromBook":[{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}},{"articleId":249449,"title":"Using Anonymous Methods in C#","slug":"using-anonymous-methods-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249449"}},{"articleId":249446,"title":"How to Seal a C# Class","slug":"seal-c-class","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249446"}}],"fromCategory":[{"articleId":289765,"title":"C# 10.0 All-in-One For Dummies Cheat Sheet","slug":"c-10-0-all-in-one-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/289765"}},{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}},{"articleId":249449,"title":"Using Anonymous Methods in C#","slug":"using-anonymous-methods-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249449"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281649,"slug":"c-7-0-all-in-one-for-dummies","isbn":"9781119428114","categoryList":["technology","programming-web-design","csharp"],"amazon":{"default":"https://www.amazon.com/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119428114-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/c-sharp-7.0-all-in-one-for-dummies-cover-9781119428114-203x255.jpg","width":203,"height":255},"title":"C# 7.0 All-in-One For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9109\">John Paul Mueller</b> is a writer on programming topics like AWS, Python, Java, HTML, CSS, and JavaScript. <b data-author-id=\"9786\">William Sempf</b> is a programmer and .NET evangelist. <b data-author-id=\"9787\">Chuck Sphar</b> was a full-time senior technical writer for the Visual C++ product group at Microsoft. </p>","authors":[{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}},{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6d80abb\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6d8137d\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":null,"lifeExpectancySetFrom":null,"dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":249455},{"headers":{"creationTime":"2018-01-31T12:45:41+00:00","modifiedTime":"2018-01-31T12:45:41+00:00","timestamp":"2022-09-14T18:16:13+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"C#","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"},"slug":"csharp","categoryId":33596}],"title":"Dividing a Single C# Program into Multiple Assemblies","strippedTitle":"dividing a single c# program into multiple assemblies","slug":"dividing-single-c-program-multiple-assemblies","canonicalUrl":"","seo":{"metaDescription":"In Visual Studio, and in C#, Visual Basic .NET, and the other .NET languages, one project equals one compiled module — otherwise known as an assembly in .NET. T","noIndex":0,"noFollow":0},"content":"In Visual Studio, and in C#, Visual Basic .NET, and the other .NET languages, one project equals one compiled <em>module</em> — otherwise known as an <em>assembly</em> in .NET. The words module and assembly have somewhat different technical meanings, but only to advanced programmers.\r\n<h2 id=\"tab1\" >Executable or library?</h2>\r\n<ul>\r\n \t<li><strong>Executable (</strong><code>.EXE</code><strong>):</strong> A program in its own right that contains a <code>Main()</code> method. You can double-click a <code>.EXE</code> file in Windows Explorer, for example, and cause it to run. Executable assemblies often use supporting code from libraries in other assemblies.</li>\r\n \t<li><strong>Class library (</strong><code>.DLL</code>strong>): A compiled library of functionality that can be used by other programs. Every program needs <code>System</code> classes. Libraries are housed in DLL assemblies.</li>\r\n</ul>\r\n<p class=\"article-tips remember\">Libraries aren’t executable — you can’t make them run directly. Instead, you must call their code from an executable or another library. The Common Language Runtime (CLR), which runs C# programs, loads library assemblies into memory as needed.</p>\r\nThe important concept to know is that you can easily write your own class libraries.\r\n<h2 id=\"tab2\" >Assemblies</h2>\r\nAssemblies, which are the compiled versions of individual projects, contain the project’s code in a special format, along with a bunch of <em>metadata,</em> or detailed information about the classes in the assembly.\r\n\r\nThis section introduces assemblies because they round out your understanding of the C# build process — and they come into play in the discussion of namespaces and access keywords such as <code>protected</code> and <code>internal</code>. Assemblies also play a big part in understanding class libraries.\r\n<p class=\"article-tips tech\">The C# compiler converts the project’s C# code to Common Intermediate Language (usually called IL) that’s stored in the appropriate type of assembly file. IL resembles assembly language (one step beyond the 1s and 0s used in machine language) that hardcore programmers have used for decades to get down “close to the metal” because their higher-level languages couldn’t do what they needed or the compilers couldn’t produce the most efficient code possible.</p>\r\nOne major consequence of compiling from .NET to IL, regardless of language, is that a program can use assemblies written in different languages. For example, a C# program can call methods in an assembly originally written in Visual Basic or C++ or the C# program can subclass a VB class.\r\n<h2 id=\"tab3\" >Executables</h2>\r\nYou can run executable assemblies in a variety of ways:\r\n<ul>\r\n \t<li>Run them in Visual Studio: Choose Debug→  Start Debugging (F5) or Debug→  Start without Debugging (Ctrl+F5).</li>\r\n \t<li>Double-click the assembly file (<code>.EXE</code>) in Windows Explorer.</li>\r\n \t<li>Right-click the file in Windows Explorer and choose Run or Open from the pop-up menu.</li>\r\n \t<li>Type the assembly’s name (and path) into a console window.</li>\r\n \t<li>If the program takes arguments, such as filenames, from the command line, drag the files to the executable file in Windows Explorer.</li>\r\n</ul>\r\n<p class=\"article-tips remember\">A solution in Visual Studio can contain multiple projects — some <code>.DLL</code> and some <code>.EXE</code>. If a solution contains more than one <code>.EXE</code> project, you must tell Visual Studio which project is the start-up project; the one runs from the Debug menu. To specify a start-up project, right-click that project in Solution Explorer and choose Set As Startup Project. The start-up project’s name appears in boldface in Solution Explorer.</p>\r\nThink of a solution containing two <code>.EXE</code> assemblies as two separate programs that happen to use the same library assemblies. For example, you might have in a solution a console executable and a Windows Forms executable plus some libraries. If you make the console app the start-up project and compile the code, you produce a console app. If you make the Windows Forms app the start-up — well, you get the idea.\r\n<h2 id=\"tab4\" >Class libraries</h2>\r\nA <em>class library</em> contains one or more classes, usually ones that work together in some way. Often, the classes in a library are in their own namespaces. You may build a library of math routines, a library of string-handling routines, and a library of input/output routines, for example.\r\n\r\nSometimes, you even build a whole solution that is nothing but a class library, rather than a program that can be executed on its own. (Typically, while developing this type of library, you also build an accompanying <code>.EXE</code> project to test your library during development. But when you release the library for programmers to use, you release just the <code>.DLL</code> (not the <code>.EXE</code>) — and documentation for it, which you can generate by writing XML comments in the code.)","description":"In Visual Studio, and in C#, Visual Basic .NET, and the other .NET languages, one project equals one compiled <em>module</em> — otherwise known as an <em>assembly</em> in .NET. The words module and assembly have somewhat different technical meanings, but only to advanced programmers.\r\n<h2 id=\"tab1\" >Executable or library?</h2>\r\n<ul>\r\n \t<li><strong>Executable (</strong><code>.EXE</code><strong>):</strong> A program in its own right that contains a <code>Main()</code> method. You can double-click a <code>.EXE</code> file in Windows Explorer, for example, and cause it to run. Executable assemblies often use supporting code from libraries in other assemblies.</li>\r\n \t<li><strong>Class library (</strong><code>.DLL</code>strong>): A compiled library of functionality that can be used by other programs. Every program needs <code>System</code> classes. Libraries are housed in DLL assemblies.</li>\r\n</ul>\r\n<p class=\"article-tips remember\">Libraries aren’t executable — you can’t make them run directly. Instead, you must call their code from an executable or another library. The Common Language Runtime (CLR), which runs C# programs, loads library assemblies into memory as needed.</p>\r\nThe important concept to know is that you can easily write your own class libraries.\r\n<h2 id=\"tab2\" >Assemblies</h2>\r\nAssemblies, which are the compiled versions of individual projects, contain the project’s code in a special format, along with a bunch of <em>metadata,</em> or detailed information about the classes in the assembly.\r\n\r\nThis section introduces assemblies because they round out your understanding of the C# build process — and they come into play in the discussion of namespaces and access keywords such as <code>protected</code> and <code>internal</code>. Assemblies also play a big part in understanding class libraries.\r\n<p class=\"article-tips tech\">The C# compiler converts the project’s C# code to Common Intermediate Language (usually called IL) that’s stored in the appropriate type of assembly file. IL resembles assembly language (one step beyond the 1s and 0s used in machine language) that hardcore programmers have used for decades to get down “close to the metal” because their higher-level languages couldn’t do what they needed or the compilers couldn’t produce the most efficient code possible.</p>\r\nOne major consequence of compiling from .NET to IL, regardless of language, is that a program can use assemblies written in different languages. For example, a C# program can call methods in an assembly originally written in Visual Basic or C++ or the C# program can subclass a VB class.\r\n<h2 id=\"tab3\" >Executables</h2>\r\nYou can run executable assemblies in a variety of ways:\r\n<ul>\r\n \t<li>Run them in Visual Studio: Choose Debug→  Start Debugging (F5) or Debug→  Start without Debugging (Ctrl+F5).</li>\r\n \t<li>Double-click the assembly file (<code>.EXE</code>) in Windows Explorer.</li>\r\n \t<li>Right-click the file in Windows Explorer and choose Run or Open from the pop-up menu.</li>\r\n \t<li>Type the assembly’s name (and path) into a console window.</li>\r\n \t<li>If the program takes arguments, such as filenames, from the command line, drag the files to the executable file in Windows Explorer.</li>\r\n</ul>\r\n<p class=\"article-tips remember\">A solution in Visual Studio can contain multiple projects — some <code>.DLL</code> and some <code>.EXE</code>. If a solution contains more than one <code>.EXE</code> project, you must tell Visual Studio which project is the start-up project; the one runs from the Debug menu. To specify a start-up project, right-click that project in Solution Explorer and choose Set As Startup Project. The start-up project’s name appears in boldface in Solution Explorer.</p>\r\nThink of a solution containing two <code>.EXE</code> assemblies as two separate programs that happen to use the same library assemblies. For example, you might have in a solution a console executable and a Windows Forms executable plus some libraries. If you make the console app the start-up project and compile the code, you produce a console app. If you make the Windows Forms app the start-up — well, you get the idea.\r\n<h2 id=\"tab4\" >Class libraries</h2>\r\nA <em>class library</em> contains one or more classes, usually ones that work together in some way. Often, the classes in a library are in their own namespaces. You may build a library of math routines, a library of string-handling routines, and a library of input/output routines, for example.\r\n\r\nSometimes, you even build a whole solution that is nothing but a class library, rather than a program that can be executed on its own. (Typically, while developing this type of library, you also build an accompanying <code>.EXE</code> project to test your library during development. But when you release the library for programmers to use, you release just the <code>.DLL</code> (not the <code>.EXE</code>) — and documentation for it, which you can generate by writing XML comments in the code.)","blurb":"","authors":[{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}},{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}}],"primaryCategoryTaxonomy":{"categoryId":33596,"title":"C#","slug":"csharp","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[{"label":"Executable or library?","target":"#tab1"},{"label":"Assemblies","target":"#tab2"},{"label":"Executables","target":"#tab3"},{"label":"Class libraries","target":"#tab4"}],"relatedArticles":{"fromBook":[{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249449,"title":"Using Anonymous Methods in C#","slug":"using-anonymous-methods-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249449"}},{"articleId":249446,"title":"How to Seal a C# Class","slug":"seal-c-class","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249446"}}],"fromCategory":[{"articleId":289765,"title":"C# 10.0 All-in-One For Dummies Cheat Sheet","slug":"c-10-0-all-in-one-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/289765"}},{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249449,"title":"Using Anonymous Methods in C#","slug":"using-anonymous-methods-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249449"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281649,"slug":"c-7-0-all-in-one-for-dummies","isbn":"9781119428114","categoryList":["technology","programming-web-design","csharp"],"amazon":{"default":"https://www.amazon.com/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119428114-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/c-sharp-7.0-all-in-one-for-dummies-cover-9781119428114-203x255.jpg","width":203,"height":255},"title":"C# 7.0 All-in-One For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9109\">John Paul Mueller</b> is a writer on programming topics like AWS, Python, Java, HTML, CSS, and JavaScript. <b data-author-id=\"9786\">William Sempf</b> is a programmer and .NET evangelist. <b data-author-id=\"9787\">Chuck Sphar</b> was a full-time senior technical writer for the Visual C++ product group at Microsoft. </p>","authors":[{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}},{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6d78b2d\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6d79453\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":null,"lifeExpectancySetFrom":null,"dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":249452},{"headers":{"creationTime":"2018-01-31T12:29:06+00:00","modifiedTime":"2018-01-31T12:29:06+00:00","timestamp":"2022-09-14T18:16:13+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"C#","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"},"slug":"csharp","categoryId":33596}],"title":"Using Anonymous Methods in C#","strippedTitle":"using anonymous methods in c#","slug":"using-anonymous-methods-c","canonicalUrl":"","seo":{"metaDescription":"After you have the gist of using delegates, take a quick look at Microsoft’s first cut at simplifying delegates in C# 2.0 a couple of years ago. To cut out some","noIndex":0,"noFollow":0},"content":"After you have the gist of using delegates, take a quick look at Microsoft’s <em>first</em> cut at simplifying delegates in C# 2.0 a couple of years ago. To cut out some of the delegate rigamarole, you can use an anonymous method. Anonymous methods are just written in more traditional notation. Although the syntax and a few details are different, the effect is essentially the same whether you use a raw delegate, an anonymous method, or a lambda expression.\r\n\r\nAn anonymous method creates the delegate instance and the method it “points” to at the same time — right in place, on the fly, <em>tout de suite.</em> Here are the guts of the <code>DoSomethingLengthy()</code> method again, this time rewritten to use an anonymous method (boldfaced):\r\n\r\n<code>private void DoSomethingLengthy() // No arguments needed this time.</code>\r\n\r\n<code>{</code>\r\n\r\n<code>...</code>\r\n\r\n<code>for (int i = 0; i &lt; duration; i++)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>if ((i % updateInterval) == 0)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>&lt;strong&gt; // Create delegate instance.&lt;/strong&gt;</code>\r\n\r\n<code>&lt;strong&gt; UpdateProgressCallback anon = delegate() &lt;/strong&gt;</code>\r\n\r\n<code>&lt;strong&gt; {&lt;/strong&gt;</code>\r\n\r\n<code>&lt;strong&gt; progressBar1.PerformStep(); // Method ‘pointed’ to&lt;/strong&gt;</code>\r\n\r\n<code>&lt;strong&gt; };&lt;/strong&gt;</code>\r\n\r\n<code>&lt;strong&gt; &lt;/strong&gt;</code>\r\n\r\n<code>if(&lt;strong&gt;anon != null&lt;/strong&gt;) &lt;strong&gt;anon()&lt;/strong&gt;; // Invoke the delegate.</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nThe code looks like standard delegate instantiations, except that after the <code>=</code> sign, you see the <code>delegate</code> keyword, any parameters to the anonymous method in parentheses (or empty parentheses if none), and the method body. The code that used to be in a separate <code>DoUpdate()</code> method — the method that the delegate “points” to — has moved inside the anonymous method — no more pointing. And this method is utterly nameless. You still need the <code>UpdateProgressCallback</code> delegate type definition, and you’re still invoking a delegate instance, named <code>anon</code> in this example.\r\n\r\nNeedless to say, this description doesn’t cover everything there is to know about anonymous methods, but it’s a start. Look up the term <em>anonymous method</em> in C# Language Help to see more anonymous method examples in the <code>DelegateExamples</code> program on the website. The best advice is to keep your anonymous methods short.","description":"After you have the gist of using delegates, take a quick look at Microsoft’s <em>first</em> cut at simplifying delegates in C# 2.0 a couple of years ago. To cut out some of the delegate rigamarole, you can use an anonymous method. Anonymous methods are just written in more traditional notation. Although the syntax and a few details are different, the effect is essentially the same whether you use a raw delegate, an anonymous method, or a lambda expression.\r\n\r\nAn anonymous method creates the delegate instance and the method it “points” to at the same time — right in place, on the fly, <em>tout de suite.</em> Here are the guts of the <code>DoSomethingLengthy()</code> method again, this time rewritten to use an anonymous method (boldfaced):\r\n\r\n<code>private void DoSomethingLengthy() // No arguments needed this time.</code>\r\n\r\n<code>{</code>\r\n\r\n<code>...</code>\r\n\r\n<code>for (int i = 0; i &lt; duration; i++)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>if ((i % updateInterval) == 0)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>&lt;strong&gt; // Create delegate instance.&lt;/strong&gt;</code>\r\n\r\n<code>&lt;strong&gt; UpdateProgressCallback anon = delegate() &lt;/strong&gt;</code>\r\n\r\n<code>&lt;strong&gt; {&lt;/strong&gt;</code>\r\n\r\n<code>&lt;strong&gt; progressBar1.PerformStep(); // Method ‘pointed’ to&lt;/strong&gt;</code>\r\n\r\n<code>&lt;strong&gt; };&lt;/strong&gt;</code>\r\n\r\n<code>&lt;strong&gt; &lt;/strong&gt;</code>\r\n\r\n<code>if(&lt;strong&gt;anon != null&lt;/strong&gt;) &lt;strong&gt;anon()&lt;/strong&gt;; // Invoke the delegate.</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nThe code looks like standard delegate instantiations, except that after the <code>=</code> sign, you see the <code>delegate</code> keyword, any parameters to the anonymous method in parentheses (or empty parentheses if none), and the method body. The code that used to be in a separate <code>DoUpdate()</code> method — the method that the delegate “points” to — has moved inside the anonymous method — no more pointing. And this method is utterly nameless. You still need the <code>UpdateProgressCallback</code> delegate type definition, and you’re still invoking a delegate instance, named <code>anon</code> in this example.\r\n\r\nNeedless to say, this description doesn’t cover everything there is to know about anonymous methods, but it’s a start. Look up the term <em>anonymous method</em> in C# Language Help to see more anonymous method examples in the <code>DelegateExamples</code> program on the website. The best advice is to keep your anonymous methods short.","blurb":"","authors":[{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}},{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}}],"primaryCategoryTaxonomy":{"categoryId":33596,"title":"C#","slug":"csharp","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}},{"articleId":249446,"title":"How to Seal a C# Class","slug":"seal-c-class","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249446"}}],"fromCategory":[{"articleId":289765,"title":"C# 10.0 All-in-One For Dummies Cheat Sheet","slug":"c-10-0-all-in-one-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/289765"}},{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281649,"slug":"c-7-0-all-in-one-for-dummies","isbn":"9781119428114","categoryList":["technology","programming-web-design","csharp"],"amazon":{"default":"https://www.amazon.com/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119428114-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/c-sharp-7.0-all-in-one-for-dummies-cover-9781119428114-203x255.jpg","width":203,"height":255},"title":"C# 7.0 All-in-One For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9109\">John Paul Mueller</b> is a writer on programming topics like AWS, Python, Java, HTML, CSS, and JavaScript. <b data-author-id=\"9786\">William Sempf</b> is a programmer and .NET evangelist. <b data-author-id=\"9787\">Chuck Sphar</b> was a full-time senior technical writer for the Visual C++ product group at Microsoft. </p>","authors":[{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}},{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6d71153\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6d71a31\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":null,"lifeExpectancySetFrom":null,"dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":249449},{"headers":{"creationTime":"2018-01-31T12:22:04+00:00","modifiedTime":"2018-01-31T12:22:04+00:00","timestamp":"2022-09-14T18:16:13+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"C#","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"},"slug":"csharp","categoryId":33596}],"title":"How to Seal a C# Class","strippedTitle":"how to seal a c# class","slug":"seal-c-class","canonicalUrl":"","seo":{"metaDescription":"You may decide that you don’t want future generations of programmers to be able to extend a particular class. You can lock the class by using the keyword sealed","noIndex":0,"noFollow":0},"content":"You may decide that you don’t want future generations of programmers to be able to extend a particular class. You can lock the class by using the keyword <code>sealed</code>. A sealed class cannot be used as the base class for any other class. Consider this code snippet:\r\nusing System;\r\n\r\n<code>public class BankAccount</code>\r\n<code>{</code>\r\n<code>// Withdrawal -- You can withdraw any amount up to the</code>\r\n<code>// balance; return the amount withdrawn</code>\r\n<code>virtual public void Withdraw(decimal withdrawal)</code>\r\n<code>{</code>\r\n<code>Console.WriteLine(\"invokes BankAccount.Withdraw()\");</code>\r\n<code>}</code>\r\n<code>}</code>\r\n\r\n<code>public sealed class SavingsAccount : BankAccount</code>\r\n<code>{</code>\r\n<code>override public void Withdraw(decimal withdrawal)</code>\r\n<code>{</code>\r\n<code>Console.WriteLine(\"invokes SavingsAccount.Withdraw()\");</code>\r\n<code>}</code>\r\n<code>}</code>\r\n\r\n<code>public class SpecialSaleAccount : SavingsAccount // Oops!</code>\r\n<code>{</code>\r\n<code>override public void Withdraw(decimal withdrawal)</code>\r\n<code>{</code>\r\n<code>Console.WriteLine(\"invokes SpecialSaleAccount.Withdraw()\");</code>\r\n<code>}</code>\r\n<code>}</code>\r\n\r\nThis snippet generates the following compiler error:\r\n<code>'SpecialSaleAccount' : cannot inherit from sealed class 'SavingsAccount'</code>\r\n\r\nYou use the <code>sealed</code> keyword to protect your class from the prying methods of a subclass. For example, allowing a programmer to extend a class that implements system security enables someone to create a security back door.\r\n\r\nSealing a class prevents another program, possibly somewhere on the Internet, from using a modified version of your class. The remote program can use the class as is, or not, but it can’t inherit bits and pieces of your class while overriding the rest.","description":"You may decide that you don’t want future generations of programmers to be able to extend a particular class. You can lock the class by using the keyword <code>sealed</code>. A sealed class cannot be used as the base class for any other class. Consider this code snippet:\r\nusing System;\r\n\r\n<code>public class BankAccount</code>\r\n<code>{</code>\r\n<code>// Withdrawal -- You can withdraw any amount up to the</code>\r\n<code>// balance; return the amount withdrawn</code>\r\n<code>virtual public void Withdraw(decimal withdrawal)</code>\r\n<code>{</code>\r\n<code>Console.WriteLine(\"invokes BankAccount.Withdraw()\");</code>\r\n<code>}</code>\r\n<code>}</code>\r\n\r\n<code>public sealed class SavingsAccount : BankAccount</code>\r\n<code>{</code>\r\n<code>override public void Withdraw(decimal withdrawal)</code>\r\n<code>{</code>\r\n<code>Console.WriteLine(\"invokes SavingsAccount.Withdraw()\");</code>\r\n<code>}</code>\r\n<code>}</code>\r\n\r\n<code>public class SpecialSaleAccount : SavingsAccount // Oops!</code>\r\n<code>{</code>\r\n<code>override public void Withdraw(decimal withdrawal)</code>\r\n<code>{</code>\r\n<code>Console.WriteLine(\"invokes SpecialSaleAccount.Withdraw()\");</code>\r\n<code>}</code>\r\n<code>}</code>\r\n\r\nThis snippet generates the following compiler error:\r\n<code>'SpecialSaleAccount' : cannot inherit from sealed class 'SavingsAccount'</code>\r\n\r\nYou use the <code>sealed</code> keyword to protect your class from the prying methods of a subclass. For example, allowing a programmer to extend a class that implements system security enables someone to create a security back door.\r\n\r\nSealing a class prevents another program, possibly somewhere on the Internet, from using a modified version of your class. The remote program can use the class as is, or not, but it can’t inherit bits and pieces of your class while overriding the rest.","blurb":"","authors":[{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}},{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}}],"primaryCategoryTaxonomy":{"categoryId":33596,"title":"C#","slug":"csharp","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}},{"articleId":249449,"title":"Using Anonymous Methods in C#","slug":"using-anonymous-methods-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249449"}}],"fromCategory":[{"articleId":289765,"title":"C# 10.0 All-in-One For Dummies Cheat Sheet","slug":"c-10-0-all-in-one-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/289765"}},{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281649,"slug":"c-7-0-all-in-one-for-dummies","isbn":"9781119428114","categoryList":["technology","programming-web-design","csharp"],"amazon":{"default":"https://www.amazon.com/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119428114-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/c-sharp-7.0-all-in-one-for-dummies-cover-9781119428114-203x255.jpg","width":203,"height":255},"title":"C# 7.0 All-in-One For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9109\">John Paul Mueller</b> is a writer on programming topics like AWS, Python, Java, HTML, CSS, and JavaScript. <b data-author-id=\"9786\">William Sempf</b> is a programmer and .NET evangelist. <b data-author-id=\"9787\">Chuck Sphar</b> was a full-time senior technical writer for the Visual C++ product group at Microsoft. </p>","authors":[{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}},{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6d695d0\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6d69eb4\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":null,"lifeExpectancySetFrom":null,"dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":249446},{"headers":{"creationTime":"2018-01-31T12:14:23+00:00","modifiedTime":"2018-01-31T12:14:23+00:00","timestamp":"2022-09-14T18:16:13+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"C#","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"},"slug":"csharp","categoryId":33596}],"title":"Using Expression-Bodied Members in C#","strippedTitle":"using expression-bodied members in c#","slug":"using-expression-bodied-members-c","canonicalUrl":"","seo":{"metaDescription":"Expression-bodied members first appeared in C# 6.0 as a means to make methods and properties easier to define. In C# 7.0, expression-bodied members also work wi","noIndex":0,"noFollow":0},"content":"Expression-bodied members first appeared in C# 6.0 as a means to make methods and properties easier to define. In C# 7.0, expression-bodied members also work with constructors, destructors, property accessors, and event accessors.\r\n<h2 id=\"tab1\" >Creating expression-bodied methods</h2>\r\nThe following example shows how you might have created a method before C# 6.0:\r\n\r\n<code>public int RectArea(Rectangle rect)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>return rect.Height * rect.Width;</code>\r\n\r\n<code>}</code>\r\n<p class=\"article-tips remember\">When working with an expression-bodied member, you can reduce the number of lines of code to just one line, like this:</p>\r\n<code>public int RectArea(Rectangle rect) => rect.Height * rect.Width;</code>\r\n\r\nEven though both versions perform precisely the same task, the second version is much shorter and easier to write. The trade-off is that the second version is also terse and can be harder to understand.\r\n<h2 id=\"tab2\" >Defining expression-bodied properties</h2>\r\nExpression-bodied properties work similarly to methods: You declare the property using a single line of code, like this:\r\n<code>public int RectArea => _rect.Height * _rect.Width;</code>\r\n\r\nThe example assumes that you have a private member named <code>_rect</code> defined and that you want to get the value that matches the rectangle’s area.\r\n<h2 id=\"tab3\" >Defining expression-bodied constructors and destructors</h2>\r\nIn C# 7.0, you can use this same technique when working with a constructor. In earlier versions of C#, you might create a constructor like this one:\r\n\r\n<code>public EmpData()</code>\r\n\r\n<code>{</code>\r\n\r\n<code>_name = \"Harvey\";</code>\r\n\r\n<code>}</code>\r\n\r\nIn this case, the <code>EmpData</code> class constructor sets a private variable, <code>_name</code>, equal to <code>\"Harvey\"</code>. The C# 7.0 version uses just one line but accomplishes the same task:\r\n\r\n<code>public EmpData() => _name = \"Harvey\";</code>\r\n\r\nDestructors work much the same as constructors. Instead of using multiple lines, you use just one line to define them.\r\n<h2 id=\"tab4\" >Defining expression-bodied property accessors</h2>\r\nProperty accessors can also benefit from the use of expression-bodied members. Here is a typical C# 6.0 property accessor with both <code>get</code> and <code>set</code> methods:</code>\r\n\r\n<code>private int _myVar;</code>\r\n\r\n<code>public MyVar</code>\r\n\r\n<code>{</code>\r\n\r\n<code>get</code>\r\n\r\n<code>{</code>\r\n\r\n<code>return _myVar;</code>\r\n\r\n<code>}</code>\r\n\r\n<code>set</code>\r\n\r\n<code>{</code>\r\n\r\n<code>SetProperty(ref _myVar, value);</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nWhen working in C# 7.0, you can shorten the code using an expression-bodied member, like this:\r\n\r\n<code>private int _myVar;</code>\r\n\r\n<code>public MyVar</code>\r\n\r\n<code>{</code>\r\n\r\n<code>get => _myVar;</code>\r\n\r\n<code>set => SetProperty(ref _myVar, value);</code>\r\n\r\n<code>}</code>\r\n<h2 id=\"tab5\" >Defining expression-bodied event accessors</h2>\r\nAs with property accessors, you can create an event accessor form using the expression-bodied member. Here’s what you might have used for C# 6.0:\r\n\r\n<code>private EventHandler _myEvent;</code>\r\n\r\n<code>public event EventHandler MyEvent</code>\r\n\r\n<code>{</code>\r\n\r\n<code>add</code>\r\n\r\n<code>{</code>\r\n\r\n<code>_myEvent += value;</code>\r\n\r\n<code>}</code>\r\n\r\n<code>remove</code>\r\n\r\n<code>{</code>\r\n\r\n<code>_myEvent -= value;</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nThe expression-bodied member form of the same event accessor in C# 7.0 looks like this:\r\n\r\n<code>private EventHandler _myEvent;</code>\r\n\r\n<code>public event EventHandler MyEvent</code>\r\n\r\n<code>{</code>\r\n\r\n<code>add => _myEvent += value;</code>\r\n\r\n<code>remove => _myEvent -= value;</code>\r\n\r\n<code>}</code>\r\n\r\n<code> </code>","description":"Expression-bodied members first appeared in C# 6.0 as a means to make methods and properties easier to define. In C# 7.0, expression-bodied members also work with constructors, destructors, property accessors, and event accessors.\r\n<h2 id=\"tab1\" >Creating expression-bodied methods</h2>\r\nThe following example shows how you might have created a method before C# 6.0:\r\n\r\n<code>public int RectArea(Rectangle rect)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>return rect.Height * rect.Width;</code>\r\n\r\n<code>}</code>\r\n<p class=\"article-tips remember\">When working with an expression-bodied member, you can reduce the number of lines of code to just one line, like this:</p>\r\n<code>public int RectArea(Rectangle rect) => rect.Height * rect.Width;</code>\r\n\r\nEven though both versions perform precisely the same task, the second version is much shorter and easier to write. The trade-off is that the second version is also terse and can be harder to understand.\r\n<h2 id=\"tab2\" >Defining expression-bodied properties</h2>\r\nExpression-bodied properties work similarly to methods: You declare the property using a single line of code, like this:\r\n<code>public int RectArea => _rect.Height * _rect.Width;</code>\r\n\r\nThe example assumes that you have a private member named <code>_rect</code> defined and that you want to get the value that matches the rectangle’s area.\r\n<h2 id=\"tab3\" >Defining expression-bodied constructors and destructors</h2>\r\nIn C# 7.0, you can use this same technique when working with a constructor. In earlier versions of C#, you might create a constructor like this one:\r\n\r\n<code>public EmpData()</code>\r\n\r\n<code>{</code>\r\n\r\n<code>_name = \"Harvey\";</code>\r\n\r\n<code>}</code>\r\n\r\nIn this case, the <code>EmpData</code> class constructor sets a private variable, <code>_name</code>, equal to <code>\"Harvey\"</code>. The C# 7.0 version uses just one line but accomplishes the same task:\r\n\r\n<code>public EmpData() => _name = \"Harvey\";</code>\r\n\r\nDestructors work much the same as constructors. Instead of using multiple lines, you use just one line to define them.\r\n<h2 id=\"tab4\" >Defining expression-bodied property accessors</h2>\r\nProperty accessors can also benefit from the use of expression-bodied members. Here is a typical C# 6.0 property accessor with both <code>get</code> and <code>set</code> methods:</code>\r\n\r\n<code>private int _myVar;</code>\r\n\r\n<code>public MyVar</code>\r\n\r\n<code>{</code>\r\n\r\n<code>get</code>\r\n\r\n<code>{</code>\r\n\r\n<code>return _myVar;</code>\r\n\r\n<code>}</code>\r\n\r\n<code>set</code>\r\n\r\n<code>{</code>\r\n\r\n<code>SetProperty(ref _myVar, value);</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nWhen working in C# 7.0, you can shorten the code using an expression-bodied member, like this:\r\n\r\n<code>private int _myVar;</code>\r\n\r\n<code>public MyVar</code>\r\n\r\n<code>{</code>\r\n\r\n<code>get => _myVar;</code>\r\n\r\n<code>set => SetProperty(ref _myVar, value);</code>\r\n\r\n<code>}</code>\r\n<h2 id=\"tab5\" >Defining expression-bodied event accessors</h2>\r\nAs with property accessors, you can create an event accessor form using the expression-bodied member. Here’s what you might have used for C# 6.0:\r\n\r\n<code>private EventHandler _myEvent;</code>\r\n\r\n<code>public event EventHandler MyEvent</code>\r\n\r\n<code>{</code>\r\n\r\n<code>add</code>\r\n\r\n<code>{</code>\r\n\r\n<code>_myEvent += value;</code>\r\n\r\n<code>}</code>\r\n\r\n<code>remove</code>\r\n\r\n<code>{</code>\r\n\r\n<code>_myEvent -= value;</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nThe expression-bodied member form of the same event accessor in C# 7.0 looks like this:\r\n\r\n<code>private EventHandler _myEvent;</code>\r\n\r\n<code>public event EventHandler MyEvent</code>\r\n\r\n<code>{</code>\r\n\r\n<code>add => _myEvent += value;</code>\r\n\r\n<code>remove => _myEvent -= value;</code>\r\n\r\n<code>}</code>\r\n\r\n<code> </code>","blurb":"","authors":[{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}},{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}}],"primaryCategoryTaxonomy":{"categoryId":33596,"title":"C#","slug":"csharp","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[{"label":"Creating expression-bodied methods","target":"#tab1"},{"label":"Defining expression-bodied properties","target":"#tab2"},{"label":"Defining expression-bodied constructors and destructors","target":"#tab3"},{"label":"Defining expression-bodied property accessors","target":"#tab4"},{"label":"Defining expression-bodied event accessors","target":"#tab5"}],"relatedArticles":{"fromBook":[{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}},{"articleId":249449,"title":"Using Anonymous Methods in C#","slug":"using-anonymous-methods-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249449"}}],"fromCategory":[{"articleId":289765,"title":"C# 10.0 All-in-One For Dummies Cheat Sheet","slug":"c-10-0-all-in-one-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/289765"}},{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281649,"slug":"c-7-0-all-in-one-for-dummies","isbn":"9781119428114","categoryList":["technology","programming-web-design","csharp"],"amazon":{"default":"https://www.amazon.com/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119428114-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/c-sharp-7.0-all-in-one-for-dummies-cover-9781119428114-203x255.jpg","width":203,"height":255},"title":"C# 7.0 All-in-One For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9109\">John Paul Mueller</b> is a writer on programming topics like AWS, Python, Java, HTML, CSS, and JavaScript. <b data-author-id=\"9786\">William Sempf</b> is a programmer and .NET evangelist. <b data-author-id=\"9787\">Chuck Sphar</b> was a full-time senior technical writer for the Visual C++ product group at Microsoft. </p>","authors":[{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}},{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6d61a7b\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6d6234e\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":null,"lifeExpectancySetFrom":null,"dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":249443},{"headers":{"creationTime":"2018-01-31T11:58:49+00:00","modifiedTime":"2018-01-31T11:58:49+00:00","timestamp":"2022-09-14T18:16:13+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"C#","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"},"slug":"csharp","categoryId":33596}],"title":"The C#-Provided Constructor","strippedTitle":"the c#-provided constructor","slug":"c-provided-constructor","canonicalUrl":"","seo":{"metaDescription":"C# keeps track of whether a variable has been initialized and doesn’t allow you to use an uninitialized variable. For example, the following code chunk generate","noIndex":0,"noFollow":0},"content":"C# keeps track of whether a variable has been initialized and doesn’t allow you to use an uninitialized variable. For example, the following code chunk generates a compile-time error:\r\n\r\n<code>public static void Main(string[] args)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>int n;</code>\r\n\r\n<code>double d;</code>\r\n\r\n<code>double calculatedValue = n + d;</code>\r\n\r\n<code>}</code>\r\n\r\nC# tracks the fact that the local variables <code>n</code> and <code>d</code> haven’t been assigned a value and doesn’t allow them to be used in the expression. Compiling this tiny program generates these compiler errors:\r\n\r\n<code>Use of unassigned local variable 'n'</code>\r\n\r\n<code>Use of unassigned local variable 'd'</code>\r\n\r\nBy comparison, C# provides a default constructor that initializes the data members of an object to\r\n<ul>\r\n \t<li>0 for numbers</li>\r\n \t<li><code>false</code> for Booleans</li>\r\n \t<li><code>null</code> for object references</li>\r\n</ul>\r\nConsider the following simple program example:\r\n\r\n<code>using System;</code>\r\n\r\n<code> </code>\r\n\r\n<code>namespace Test</code>\r\n\r\n<code>{</code>\r\n\r\n<code>public class Program</code>\r\n\r\n<code>{</code>\r\n\r\n<code>public static void Main(string[] args)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>// First create an object.</code>\r\n\r\n<code>MyObject localObject = new MyObject();</code>\r\n\r\n<code>Console.WriteLine(\"localObject.n is {0}\", localObject.n);</code>\r\n\r\n<code> </code>\r\n\r\n<code>if (localObject.nextObject == null)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>Console.WriteLine(\"localObject.nextObject is null\");</code>\r\n\r\n<code>}</code>\r\n\r\n<code> </code>\r\n\r\n<code>// Wait for user to acknowledge the results.</code>\r\n\r\n<code>Console.WriteLine(\"Press Enter to terminate...\");</code>\r\n\r\n<code>Console.Read();</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\n<code> </code>\r\n\r\n<code>public class MyObject</code>\r\n\r\n<code>{</code>\r\n\r\n<code>internal int n;</code>\r\n\r\n<code>internal MyObject nextObject;</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nThis program defines a class <code>MyObject</code>, which contains both a simple data member <code>n</code> of type <code>int</code> and a reference to an object, <code>nextObject</code> (both declared <code>internal</code>). The <code>Main()</code> method creates a <code>MyObject</code> and then displays the initial contents of <code>n</code> and <code>nextObject</code>. The output from executing the program appears this way:\r\n\r\n<code>localObject.n is 0</code>\r\n\r\n<code>localObject.nextObject is null</code>\r\n\r\n<code>Press Enter to terminate...</code>\r\n\r\nWhen the object is created, C# executes a small piece of code that the compiler provides to initialize the object and its members. Left to their own devices, the data members <code>localObject.n</code> and <code>nextObject</code> would contain random, garbage values.\r\n<p class=\"article-tips remember\">The code that initializes values when they’re created is the default constructor. It constructs the class, in the sense of initializing its members. Thus C# ensures that an object starts life in a known state: all zeros, nulls, or false values, depending on type. This concept affects only data members of the class, not local variables in a method.</p>","description":"C# keeps track of whether a variable has been initialized and doesn’t allow you to use an uninitialized variable. For example, the following code chunk generates a compile-time error:\r\n\r\n<code>public static void Main(string[] args)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>int n;</code>\r\n\r\n<code>double d;</code>\r\n\r\n<code>double calculatedValue = n + d;</code>\r\n\r\n<code>}</code>\r\n\r\nC# tracks the fact that the local variables <code>n</code> and <code>d</code> haven’t been assigned a value and doesn’t allow them to be used in the expression. Compiling this tiny program generates these compiler errors:\r\n\r\n<code>Use of unassigned local variable 'n'</code>\r\n\r\n<code>Use of unassigned local variable 'd'</code>\r\n\r\nBy comparison, C# provides a default constructor that initializes the data members of an object to\r\n<ul>\r\n \t<li>0 for numbers</li>\r\n \t<li><code>false</code> for Booleans</li>\r\n \t<li><code>null</code> for object references</li>\r\n</ul>\r\nConsider the following simple program example:\r\n\r\n<code>using System;</code>\r\n\r\n<code> </code>\r\n\r\n<code>namespace Test</code>\r\n\r\n<code>{</code>\r\n\r\n<code>public class Program</code>\r\n\r\n<code>{</code>\r\n\r\n<code>public static void Main(string[] args)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>// First create an object.</code>\r\n\r\n<code>MyObject localObject = new MyObject();</code>\r\n\r\n<code>Console.WriteLine(\"localObject.n is {0}\", localObject.n);</code>\r\n\r\n<code> </code>\r\n\r\n<code>if (localObject.nextObject == null)</code>\r\n\r\n<code>{</code>\r\n\r\n<code>Console.WriteLine(\"localObject.nextObject is null\");</code>\r\n\r\n<code>}</code>\r\n\r\n<code> </code>\r\n\r\n<code>// Wait for user to acknowledge the results.</code>\r\n\r\n<code>Console.WriteLine(\"Press Enter to terminate...\");</code>\r\n\r\n<code>Console.Read();</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\n<code> </code>\r\n\r\n<code>public class MyObject</code>\r\n\r\n<code>{</code>\r\n\r\n<code>internal int n;</code>\r\n\r\n<code>internal MyObject nextObject;</code>\r\n\r\n<code>}</code>\r\n\r\n<code>}</code>\r\n\r\nThis program defines a class <code>MyObject</code>, which contains both a simple data member <code>n</code> of type <code>int</code> and a reference to an object, <code>nextObject</code> (both declared <code>internal</code>). The <code>Main()</code> method creates a <code>MyObject</code> and then displays the initial contents of <code>n</code> and <code>nextObject</code>. The output from executing the program appears this way:\r\n\r\n<code>localObject.n is 0</code>\r\n\r\n<code>localObject.nextObject is null</code>\r\n\r\n<code>Press Enter to terminate...</code>\r\n\r\nWhen the object is created, C# executes a small piece of code that the compiler provides to initialize the object and its members. Left to their own devices, the data members <code>localObject.n</code> and <code>nextObject</code> would contain random, garbage values.\r\n<p class=\"article-tips remember\">The code that initializes values when they’re created is the default constructor. It constructs the class, in the sense of initializing its members. Thus C# ensures that an object starts life in a known state: all zeros, nulls, or false values, depending on type. This concept affects only data members of the class, not local variables in a method.</p>","blurb":"","authors":[{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}},{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}}],"primaryCategoryTaxonomy":{"categoryId":33596,"title":"C#","slug":"csharp","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33596"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":[{"articleId":192609,"title":"How to Pray the Rosary: A Comprehensive Guide","slug":"how-to-pray-the-rosary","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/192609"}},{"articleId":208741,"title":"Kabbalah For Dummies Cheat Sheet","slug":"kabbalah-for-dummies-cheat-sheet","categoryList":["body-mind-spirit","religion-spirituality","kabbalah"],"_links":{"self":"/articles/208741"}},{"articleId":230957,"title":"Nikon D3400 For Dummies Cheat Sheet","slug":"nikon-d3400-dummies-cheat-sheet","categoryList":["home-auto-hobbies","photography"],"_links":{"self":"/articles/230957"}},{"articleId":235851,"title":"Praying the Rosary and Meditating on the Mysteries","slug":"praying-rosary-meditating-mysteries","categoryList":["body-mind-spirit","religion-spirituality","christianity","catholicism"],"_links":{"self":"/articles/235851"}},{"articleId":284787,"title":"What Your Society Says About You","slug":"what-your-society-says-about-you","categoryList":["academics-the-arts","humanities"],"_links":{"self":"/articles/284787"}}],"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}},{"articleId":249449,"title":"Using Anonymous Methods in C#","slug":"using-anonymous-methods-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249449"}}],"fromCategory":[{"articleId":289765,"title":"C# 10.0 All-in-One For Dummies Cheat Sheet","slug":"c-10-0-all-in-one-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/289765"}},{"articleId":249507,"title":"Making Sure Your ASP.NET Site Is Accessible","slug":"making-sure-asp-net-site-accessible","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249507"}},{"articleId":249504,"title":"Employing Dynamic C# Programming Techniques","slug":"employing-dynamic-c-programming-techniques","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249504"}},{"articleId":249455,"title":"Using Structures as Records in C#","slug":"using-structures-records-c","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249455"}},{"articleId":249452,"title":"Dividing a Single C# Program into Multiple Assemblies","slug":"dividing-single-c-program-multiple-assemblies","categoryList":["technology","programming-web-design","csharp"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/249452"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281649,"slug":"c-7-0-all-in-one-for-dummies","isbn":"9781119428114","categoryList":["technology","programming-web-design","csharp"],"amazon":{"default":"https://www.amazon.com/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119428114-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119428114/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/c-sharp-7.0-all-in-one-for-dummies-cover-9781119428114-203x255.jpg","width":203,"height":255},"title":"C# 7.0 All-in-One For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9109\">John Paul Mueller</b> is a writer on programming topics like AWS, Python, Java, HTML, CSS, and JavaScript. <b data-author-id=\"9786\">William Sempf</b> is a programmer and .NET evangelist. <b data-author-id=\"9787\">Chuck Sphar</b> was a full-time senior technical writer for the Visual C++ product group at Microsoft. </p>","authors":[{"authorId":9786,"name":"Bill Sempf","slug":"bill-sempf","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9786"}},{"authorId":9787,"name":"Chuck Sphar","slug":"chuck-sphar","description":" <p><b>Bill Sempf</b> is a seasoned programmer and .NET evangelist specializing in .NET applications. <b>Chuck Sphar</b> is a programmer and former senior technical writer for the Visual C&#43;&#43; product group at Microsoft. <b>Stephen Randy Davis</b> is the bestselling author of several books, including <i>C&#43;&#43; For Dummies.</i> ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9787"}},{"authorId":9109,"name":"John Paul Mueller","slug":"john-paul-mueller","description":" <p><b>John Mueller</b> has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services &#40;AWS&#41;. <b>Luca Massaron,</b> a Google Developer Expert &#40;GDE&#41;,??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques. ","hasArticle":false,"_links":{"self":"https://dummies-api.dummies.com/v2/authors/9109"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6d59984\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;csharp&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119428114&quot;]}]\" id=\"du-slot-63221a6d5a1f5\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":null,"lifeExpectancySetFrom":null,"dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":249440}],"_links":{"self":{"self":"https://dummies-api.dummies.com/v2/categories/33596/categoryArticles?sortField=time&sortOrder=1&size=10&offset=0"},"next":{"self":"https://dummies-api.dummies.com/v2/categories/33596/categoryArticles?sortField=time&sortOrder=1&size=10&offset=10"},"last":{"self":"https://dummies-api.dummies.com/v2/categories/33596/categoryArticles?sortField=time&sortOrder=1&size=10&offset=19"}}},"objectTitle":"","status":"success","pageType":"article-category","objectId":"33596","page":1,"sortField":"time","sortOrder":1,"categoriesIds":[],"articleTypes":[],"filterData":{"categoriesFilter":[{"itemId":0,"itemName":"All Categories","count":29}],"articleTypeFilter":[{"articleType":"All Types","count":29},{"articleType":"Articles","count":27},{"articleType":"Cheat Sheet","count":2}]},"filterDataLoadedStatus":"success","pageSize":10},"adsState":{"pageScripts":{"headers":{"timestamp":"2025-04-17T15:50:01+00:00"},"adsId":0,"data":{"scripts":[{"pages":["all"],"location":"header","script":"<!--Optimizely Script-->\r\n<script src=\"https://cdn.optimizely.com/js/10563184655.js\"></script>","enabled":false},{"pages":["all"],"location":"header","script":"<!-- comScore Tag -->\r\n<script>var _comscore = _comscore || [];_comscore.push({ c1: \"2\", c2: \"15097263\" });(function() {var s = document.createElement(\"script\"), el = document.getElementsByTagName(\"script\")[0]; s.async = true;s.src = (document.location.protocol == \"https:\" ? \"https://sb\" : \"http://b\") + \".scorecardresearch.com/beacon.js\";el.parentNode.insertBefore(s, el);})();</script><noscript><img src=\"https://sb.scorecardresearch.com/p?c1=2&c2=15097263&cv=2.0&cj=1\" /></noscript>\r\n<!-- / comScore Tag -->","enabled":true},{"pages":["all"],"location":"footer","script":"<!--BEGIN QUALTRICS WEBSITE FEEDBACK SNIPPET-->\r\n<script type='text/javascript'>\r\n(function(){var g=function(e,h,f,g){\r\nthis.get=function(a){for(var a=a+\"=\",c=document.cookie.split(\";\"),b=0,e=c.length;b<e;b++){for(var d=c[b];\" \"==d.charAt(0);)d=d.substring(1,d.length);if(0==d.indexOf(a))return d.substring(a.length,d.length)}return null};\r\nthis.set=function(a,c){var b=\"\",b=new Date;b.setTime(b.getTime()+6048E5);b=\"; expires=\"+b.toGMTString();document.cookie=a+\"=\"+c+b+\"; path=/; \"};\r\nthis.check=function(){var a=this.get(f);if(a)a=a.split(\":\");else if(100!=e)\"v\"==h&&(e=Math.random()>=e/100?0:100),a=[h,e,0],this.set(f,a.join(\":\"));else return!0;var c=a[1];if(100==c)return!0;switch(a[0]){case \"v\":return!1;case \"r\":return c=a[2]%Math.floor(100/c),a[2]++,this.set(f,a.join(\":\")),!c}return!0};\r\nthis.go=function(){if(this.check()){var a=document.createElement(\"script\");a.type=\"text/javascript\";a.src=g;document.body&&document.body.appendChild(a)}};\r\nthis.start=function(){var t=this;\"complete\"!==document.readyState?window.addEventListener?window.addEventListener(\"load\",function(){t.go()},!1):window.attachEvent&&window.attachEvent(\"onload\",function(){t.go()}):t.go()};};\r\ntry{(new g(100,\"r\",\"QSI_S_ZN_5o5yqpvMVjgDOuN\",\"https://zn5o5yqpvmvjgdoun-wiley.siteintercept.qualtrics.com/SIE/?Q_ZID=ZN_5o5yqpvMVjgDOuN\")).start()}catch(i){}})();\r\n</script><div id='ZN_5o5yqpvMVjgDOuN'><!--DO NOT REMOVE-CONTENTS PLACED HERE--></div>\r\n<!--END WEBSITE FEEDBACK SNIPPET-->","enabled":false},{"pages":["all"],"location":"header","script":"<!-- Hotjar Tracking Code for http://www.dummies.com -->\r\n<script>\r\n (function(h,o,t,j,a,r){\r\n h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};\r\n h._hjSettings={hjid:257151,hjsv:6};\r\n a=o.getElementsByTagName('head')[0];\r\n r=o.createElement('script');r.async=1;\r\n r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;\r\n a.appendChild(r);\r\n })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');\r\n</script>","enabled":false},{"pages":["article"],"location":"header","script":"<!-- //Connect Container: dummies --> <script src=\"//get.s-onetag.com/bffe21a1-6bb8-4928-9449-7beadb468dae/tag.min.js\" async defer></script>","enabled":true},{"pages":["homepage"],"location":"header","script":"<meta name=\"facebook-domain-verification\" content=\"irk8y0irxf718trg3uwwuexg6xpva0\" />","enabled":true},{"pages":["homepage","article","category","search"],"location":"footer","script":"<!-- Facebook Pixel Code -->\r\n<noscript>\r\n<img height=\"1\" width=\"1\" src=\"https://www.facebook.com/tr?id=256338321977984&ev=PageView&noscript=1\"/>\r\n</noscript>\r\n<!-- End Facebook Pixel Code -->","enabled":true}]}},"pageScriptsLoadedStatus":"success"},"navigationState":{"navigationCollections":[{"collectionId":287568,"title":"BYOB (Be Your Own Boss)","hasSubCategories":false,"url":"/collection/for-the-entry-level-entrepreneur-287568"},{"collectionId":293237,"title":"Be a Rad Dad","hasSubCategories":false,"url":"/collection/be-the-best-dad-293237"},{"collectionId":295890,"title":"Career Shifting","hasSubCategories":false,"url":"/collection/career-shifting-295890"},{"collectionId":294090,"title":"Contemplating the Cosmos","hasSubCategories":false,"url":"/collection/theres-something-about-space-294090"},{"collectionId":287563,"title":"For Those Seeking Peace of Mind","hasSubCategories":false,"url":"/collection/for-those-seeking-peace-of-mind-287563"},{"collectionId":287570,"title":"For the Aspiring Aficionado","hasSubCategories":false,"url":"/collection/for-the-bougielicious-287570"},{"collectionId":291903,"title":"For the Budding Cannabis Enthusiast","hasSubCategories":false,"url":"/collection/for-the-budding-cannabis-enthusiast-291903"},{"collectionId":299891,"title":"For the College Bound","hasSubCategories":false,"url":"/collection/for-the-college-bound-299891"},{"collectionId":291934,"title":"For the Exam-Season Crammer","hasSubCategories":false,"url":"/collection/for-the-exam-season-crammer-291934"},{"collectionId":301547,"title":"For the Game Day Prepper","hasSubCategories":false,"url":"/collection/big-game-day-prep-made-easy-301547"}],"navigationCollectionsLoadedStatus":"success","navigationCategories":{"books":{"0":{"data":[{"categoryId":33512,"title":"Technology","hasSubCategories":true,"url":"/category/books/technology-33512"},{"categoryId":33662,"title":"Academics & The Arts","hasSubCategories":true,"url":"/category/books/academics-the-arts-33662"},{"categoryId":33809,"title":"Home, Auto, & Hobbies","hasSubCategories":true,"url":"/category/books/home-auto-hobbies-33809"},{"categoryId":34038,"title":"Body, Mind, & Spirit","hasSubCategories":true,"url":"/category/books/body-mind-spirit-34038"},{"categoryId":34224,"title":"Business, Careers, & Money","hasSubCategories":true,"url":"/category/books/business-careers-money-34224"}],"breadcrumbs":[],"categoryTitle":"Level 0 Category","mainCategoryUrl":"/category/books/level-0-category-0"}},"articles":{"0":{"data":[{"categoryId":33512,"title":"Technology","hasSubCategories":true,"url":"/category/articles/technology-33512"},{"categoryId":33662,"title":"Academics & The Arts","hasSubCategories":true,"url":"/category/articles/academics-the-arts-33662"},{"categoryId":33809,"title":"Home, Auto, & Hobbies","hasSubCategories":true,"url":"/category/articles/home-auto-hobbies-33809"},{"categoryId":34038,"title":"Body, Mind, & Spirit","hasSubCategories":true,"url":"/category/articles/body-mind-spirit-34038"},{"categoryId":34224,"title":"Business, Careers, & Money","hasSubCategories":true,"url":"/category/articles/business-careers-money-34224"}],"breadcrumbs":[],"categoryTitle":"Level 0 Category","mainCategoryUrl":"/category/articles/level-0-category-0"}}},"navigationCategoriesLoadedStatus":"success"},"searchState":{"searchList":[],"searchStatus":"initial","relatedArticlesList":[],"relatedArticlesStatus":"initial"},"routeState":{"name":"ArticleCategory","path":"/category/articles/csharp-33596/","hash":"","query":{},"params":{"category":"csharp-33596"},"fullPath":"/category/articles/csharp-33596/","meta":{"routeType":"category","breadcrumbInfo":{"suffix":"Articles","baseRoute":"/category/articles"},"prerenderWithAsyncData":true},"from":{"name":null,"path":"/","hash":"","query":{},"params":{},"fullPath":"/","meta":{}}},"profileState":{"auth":{},"userOptions":{},"status":"success"}}
Logo
  • Articles Open Article Categories
  • Books Open Book Categories
  • Collections Open Collections list
  • Custom Solutions

Article Categories

Book Categories

Collections

Explore all collections
BYOB (Be Your Own Boss)
Be a Rad Dad
Career Shifting
Contemplating the Cosmos
For Those Seeking Peace of Mind
For the Aspiring Aficionado
For the Budding Cannabis Enthusiast
For the College Bound
For the Exam-Season Crammer
For the Game Day Prepper
Log In
  • Home
  • Technology Articles
  • Programming & Web Design Articles
  • C# Articles

C# Articles

C# (pronounced "see sharp") is like C's cooler cousin. Simplified and streamlined, this programming language is still crazy-powerful.

Articles From C#

page 1
page 2
page 3

Filter Results

29 results
29 results
C# C# 7.0 All-In-One For Dummies Cheat Sheet

Cheat Sheet / Updated 03-10-2022

C# provides you with access to a phenomenal array of programming options. Use this cheat sheet to help you get the job done faster and easier when using C# as your development solution of choice.

View Cheat Sheet
C# C# 10.0 All-in-One For Dummies Cheat Sheet

Cheat Sheet / Updated 12-08-2021

C# provides you with access to a phenomenal array of programming options. Use this cheat sheet to help you get the job done faster and easier when using C# as your development solution of choice.

View Cheat Sheet
C# Making Sure Your ASP.NET Site Is Accessible

Article / Updated 02-01-2018

Everyone has special needs, and those needs change as time progresses. Microsoft is aware of this. Someone with perfect eyesight in the morning might suffer from tired eyes in the afternoon. Many web users have some sort of special need all the time. Whether the need is intermittent or constant, making your site accessible means making it easy for everyone to use. Microsoft has made a significant investment in accessible web browsing, and you’ll be pleased to find that most of the controls make good decisions about accessibility right out of the box. Understanding how to use them for this purpose takes a little effort, however. If you’re building websites for large enterprises or the government, Section 508 (an amendment to the Rehabilitation Act) makes this very important. Check out Accessibility for Everybody, by John Paul Mueller (Apress) for more information. Most ASP.NET controls, where applicable, fit a certain feature list for accessibility. The goal is to make coding for accessibility easy for the programmer and functional for the user. Any element that isn’t made of text should have an alternate text option. For instance, all image tags support an AlternateText property, which populates the HTML alt tag. web-to-text readers will “speak” the contents of this tag in place of the image. If you add an image to a web page, Visual Studio even prompts you for the alternate text. Controls don’t require the use of style sheets or color dependency. If you want, you can easily strip all style information from a page for simplicity of use by a reader or a low-sight version of the application. All input controls in Getting Input from the User support a TabIndex property, which allows users to tab from control to control. For those not using a mouse, this is optimum. Setting which part of the form has the cursor by default (called default focus) is easy in ASP.NET with the DefaultFocus property. Changing it is easy with the SetFocus method. You can give buttons keyboard equivalents by using the AccessKey property. Labels and input controls can be associated, which many web readers depend on. A feature in Visual Studio called Check Page for Accessibility checks web Content Accessibility Guidelines (WCAG) and Section 508 errors. If you use this feature, warnings will actually be posted to your build process.

View Article
C# Employing Dynamic C# Programming Techniques

Article / Updated 02-01-2018

When you define a new variable, you can use the dynamic keyword, and C# will let you make assumptions about the members of the variable. For example, if you want to declare a new Course object, you do it like this: Course newCourse = new Course(); newCourse.Schedule(); This is, of course, assuming that you have a Course class defined somewhere else in your program, like this: class Course { public void Schedule() { //Something fancy here } } But what if you don't know what class the new object will be? How do you handle that? You could declare it as an Object, because everything derives from Object, right? Here's the code: Object newCourse = new Object(); Not so fast, if you make your next line this: newCourse.Schedule(); Note the squiggly line appears almost immediately, and you get the famous “object does not contain a definition for Schedule…” error in the design time Error List. However, you can do this: dynamic newCourse = SomeFunction(); newCourse.Schedule(); All this code needs to have is the stub of a function that returns some value, and you are good to go. What if SomeFunction() returns a string? Well, you get a runtime error. But it will still compile! About now you may be thinking: “This is a good thing? How!?!” For the time being, you can blame COM. You see, COM was mostly constructed using C++, which has a variant type. In C++, you could declare a variable to be dynamic, like this: VARIANT newCourse; It worked just like the dynamic type, except C# wasn't invented yet. Anyway, because a lot of the objects in COM used VARIANT out parameters, it was really tough to handle Interop using .NET. Because Microsoft Office is mostly made of COM objects, and because it isn't going to change any time soon, and because Microsoft all C# programmers to be Office developers one day, bam, you have the dynamic type. Say, for instance, that your newCourse is a variant out parameter from a method in a COM class. To get the value, you have to declare it an Object, like this: CourseMarshaller cm = new CourseMarshaller(); //a COM object int courseId = 4; Object newCourse; cm.MakeCourse(courseId, newCourse); //and now we are back to square one newCourse.Schedule(); //This causes a 'member not found exception' Line 6 will not compile, even if the Schedule method exists, because you can't assume that newCourse will always come back as a Course object, because it is declared a variant. You’re stuck. With a dynamic type, though, you’re golden once again, with this code: CourseMarshaller cm = new CourseMarshaller(); //a COM object int courseId = 4; dynamic newCourse; cm.MakeCourse(courseId, newCourse); newCourse.Schedule(); //This now compiles What happens if newCourse comes back as something that doesn't have a Schedule method? You get a runtime error. But there are try/catch blocks for runtime errors. Nothing will help it compile without the dynamic keyword. Readers who are long-time Visual Basic programmers, or even newer VB.NET programmers, realize that you can handle this dynamically — and have always been able to — in Visual Basic. Some developers recommend that programmers who work with legacy systems use Visual Basic for their new code, and this is exactly why. In the interest of language parity, now C# can do it, too. In general, this is good, because many organizations are writing legacy code in VB and new code in C# — and it can get pretty messy in the trenches. This change makes the code base slimmer.

View Article
C# Using Structures as Records in C#

Article / Updated 01-31-2018

The main reason to work with structures in most code is to create records that contain custom data. You use these custom data records to hold complex information and pass it around as needed within your application. It’s easier and faster to pass a single record than it is to pass a collection of data values, especially when your application performs the task regularly. Keep reading to find out how to use structures as a kind of data record. Managing a single record Passing structures to methods is cleaner and easier than passing a collection of individual data values. Of course, the values in the structure must be related in order for this strategy to work well. However, consider the following method: static void DisplayMessage(Message msg) { Console.WriteLine( "In response to Msg {0}, you can get {1} of {2} for {3}.", msg.MsgID, msg.Qty, msg.ProductID, msg.Price); } In this case, the DisplayMessage() method receives a single input of type Message instead of the four variables that the method would normally require. Using the Message structure produces these positive results in the code: The receiving method can assume that all the required data values are present. The receiving method can assume that all the variables are initialized. The caller is less likely to create erroneous code. Other developers can read the code with greater ease. Code changes are easier to make. Adding structures to arrays Applications rarely use a single data record for every purpose. In most cases, applications also include database-like collections of records. For example, an application is unlikely to receive just one Message. Instead, the application will likely receive a group of Message records, each of which it must process. You can add structures to any collection. However, most collections work with objects, so adding a structure to them would incur a performance penalty because C# must box and unbox each structure individually. As the size of the collection increases, the penalty becomes quite noticeable. Consequently, it’s always a better idea to restrict collections of data records that rely on structures to arrays in your application when speed is the most important concern. Working with an array of structures is much like working with an array of anything else. You could use code like this to create an array of Message structures: // Display all the messages on screen. Message[] Msgs = { myMsg, myMsg2 }; DisplayMessages(Msgs); In this case, Msgs contains two records, myMsg and myMsg2. The code then processes the messages by passing the array to DisplayMessages(), which is shown here: static void DisplayMessages(Message[] msgs) { foreach (Message item in msgs) { Console.WriteLine( "In response to Msg {0}, you can get {1} of {2} for {3}.", item.MsgID, item.Qty, item.ProductID, item.Price); } } The DisplayMessages() method uses a foreach loop to separate the individual Message records. It then processes them using the same approach as DisplayMessage(). Overriding methods Structures provide a great deal of flexibility that many developers assign exclusively to classes. For example, you can override methods, often in ways that make the structure output infinitely better. A good example is the ToString() method, which outputs a somewhat unhelpful (or something similar): Structures.Program+Messages The output isn’t useful because it doesn’t tell you anything. To garner anything useful, you must override the ToString() method by using code like this: public override string ToString() { // Create a useful output string. return "Message ID:\t" + MsgID + "\r\nProduct ID:\t" + ProductID + "\r\nQuantity:\t" + Qty + "\r\nTotal Price:\t" + Price; } Now when you call ToString(), you obtain useful information. In this case, you see the following output when calling myMsg.ToString(): Message ID: 1 Product ID: 22 Quantity: 5 Total Price: 29.95

View Article
C# Dividing a Single C# Program into Multiple Assemblies

Article / Updated 01-31-2018

In Visual Studio, and in C#, Visual Basic .NET, and the other .NET languages, one project equals one compiled module — otherwise known as an assembly in .NET. The words module and assembly have somewhat different technical meanings, but only to advanced programmers. Executable or library? Executable (.EXE): A program in its own right that contains a Main() method. You can double-click a .EXE file in Windows Explorer, for example, and cause it to run. Executable assemblies often use supporting code from libraries in other assemblies. Class library (.DLLstrong>): A compiled library of functionality that can be used by other programs. Every program needs System classes. Libraries are housed in DLL assemblies. Libraries aren’t executable — you can’t make them run directly. Instead, you must call their code from an executable or another library. The Common Language Runtime (CLR), which runs C# programs, loads library assemblies into memory as needed. The important concept to know is that you can easily write your own class libraries. Assemblies Assemblies, which are the compiled versions of individual projects, contain the project’s code in a special format, along with a bunch of metadata, or detailed information about the classes in the assembly. This section introduces assemblies because they round out your understanding of the C# build process — and they come into play in the discussion of namespaces and access keywords such as protected and internal. Assemblies also play a big part in understanding class libraries. The C# compiler converts the project’s C# code to Common Intermediate Language (usually called IL) that’s stored in the appropriate type of assembly file. IL resembles assembly language (one step beyond the 1s and 0s used in machine language) that hardcore programmers have used for decades to get down “close to the metal” because their higher-level languages couldn’t do what they needed or the compilers couldn’t produce the most efficient code possible. One major consequence of compiling from .NET to IL, regardless of language, is that a program can use assemblies written in different languages. For example, a C# program can call methods in an assembly originally written in Visual Basic or C++ or the C# program can subclass a VB class. Executables You can run executable assemblies in a variety of ways: Run them in Visual Studio: Choose Debug→  Start Debugging (F5) or Debug→  Start without Debugging (Ctrl+F5). Double-click the assembly file (.EXE) in Windows Explorer. Right-click the file in Windows Explorer and choose Run or Open from the pop-up menu. Type the assembly’s name (and path) into a console window. If the program takes arguments, such as filenames, from the command line, drag the files to the executable file in Windows Explorer. A solution in Visual Studio can contain multiple projects — some .DLL and some .EXE. If a solution contains more than one .EXE project, you must tell Visual Studio which project is the start-up project; the one runs from the Debug menu. To specify a start-up project, right-click that project in Solution Explorer and choose Set As Startup Project. The start-up project’s name appears in boldface in Solution Explorer. Think of a solution containing two .EXE assemblies as two separate programs that happen to use the same library assemblies. For example, you might have in a solution a console executable and a Windows Forms executable plus some libraries. If you make the console app the start-up project and compile the code, you produce a console app. If you make the Windows Forms app the start-up — well, you get the idea. Class libraries A class library contains one or more classes, usually ones that work together in some way. Often, the classes in a library are in their own namespaces. You may build a library of math routines, a library of string-handling routines, and a library of input/output routines, for example. Sometimes, you even build a whole solution that is nothing but a class library, rather than a program that can be executed on its own. (Typically, while developing this type of library, you also build an accompanying .EXE project to test your library during development. But when you release the library for programmers to use, you release just the .DLL (not the .EXE) — and documentation for it, which you can generate by writing XML comments in the code.)

View Article
C# Using Anonymous Methods in C#

Article / Updated 01-31-2018

After you have the gist of using delegates, take a quick look at Microsoft’s first cut at simplifying delegates in C# 2.0 a couple of years ago. To cut out some of the delegate rigamarole, you can use an anonymous method. Anonymous methods are just written in more traditional notation. Although the syntax and a few details are different, the effect is essentially the same whether you use a raw delegate, an anonymous method, or a lambda expression. An anonymous method creates the delegate instance and the method it “points” to at the same time — right in place, on the fly, tout de suite. Here are the guts of the DoSomethingLengthy() method again, this time rewritten to use an anonymous method (boldfaced): private void DoSomethingLengthy() // No arguments needed this time. { ... for (int i = 0; i < duration; i++) { if ((i % updateInterval) == 0) { <strong> // Create delegate instance.</strong> <strong> UpdateProgressCallback anon = delegate() </strong> <strong> {</strong> <strong> progressBar1.PerformStep(); // Method ‘pointed’ to</strong> <strong> };</strong> <strong> </strong> if(<strong>anon != null</strong>) <strong>anon()</strong>; // Invoke the delegate. } } } The code looks like standard delegate instantiations, except that after the = sign, you see the delegate keyword, any parameters to the anonymous method in parentheses (or empty parentheses if none), and the method body. The code that used to be in a separate DoUpdate() method — the method that the delegate “points” to — has moved inside the anonymous method — no more pointing. And this method is utterly nameless. You still need the UpdateProgressCallback delegate type definition, and you’re still invoking a delegate instance, named anon in this example. Needless to say, this description doesn’t cover everything there is to know about anonymous methods, but it’s a start. Look up the term anonymous method in C# Language Help to see more anonymous method examples in the DelegateExamples program on the website. The best advice is to keep your anonymous methods short.

View Article
C# How to Seal a C# Class

Article / Updated 01-31-2018

You may decide that you don’t want future generations of programmers to be able to extend a particular class. You can lock the class by using the keyword sealed. A sealed class cannot be used as the base class for any other class. Consider this code snippet: using System; public class BankAccount { // Withdrawal -- You can withdraw any amount up to the // balance; return the amount withdrawn virtual public void Withdraw(decimal withdrawal) { Console.WriteLine("invokes BankAccount.Withdraw()"); } } public sealed class SavingsAccount : BankAccount { override public void Withdraw(decimal withdrawal) { Console.WriteLine("invokes SavingsAccount.Withdraw()"); } } public class SpecialSaleAccount : SavingsAccount // Oops! { override public void Withdraw(decimal withdrawal) { Console.WriteLine("invokes SpecialSaleAccount.Withdraw()"); } } This snippet generates the following compiler error: 'SpecialSaleAccount' : cannot inherit from sealed class 'SavingsAccount' You use the sealed keyword to protect your class from the prying methods of a subclass. For example, allowing a programmer to extend a class that implements system security enables someone to create a security back door. Sealing a class prevents another program, possibly somewhere on the Internet, from using a modified version of your class. The remote program can use the class as is, or not, but it can’t inherit bits and pieces of your class while overriding the rest.

View Article
C# Using Expression-Bodied Members in C#

Article / Updated 01-31-2018

Expression-bodied members first appeared in C# 6.0 as a means to make methods and properties easier to define. In C# 7.0, expression-bodied members also work with constructors, destructors, property accessors, and event accessors. Creating expression-bodied methods The following example shows how you might have created a method before C# 6.0: public int RectArea(Rectangle rect) { return rect.Height * rect.Width; } When working with an expression-bodied member, you can reduce the number of lines of code to just one line, like this: public int RectArea(Rectangle rect) => rect.Height * rect.Width; Even though both versions perform precisely the same task, the second version is much shorter and easier to write. The trade-off is that the second version is also terse and can be harder to understand. Defining expression-bodied properties Expression-bodied properties work similarly to methods: You declare the property using a single line of code, like this: public int RectArea => _rect.Height * _rect.Width; The example assumes that you have a private member named _rect defined and that you want to get the value that matches the rectangle’s area. Defining expression-bodied constructors and destructors In C# 7.0, you can use this same technique when working with a constructor. In earlier versions of C#, you might create a constructor like this one: public EmpData() { _name = "Harvey"; } In this case, the EmpData class constructor sets a private variable, _name, equal to "Harvey". The C# 7.0 version uses just one line but accomplishes the same task: public EmpData() => _name = "Harvey"; Destructors work much the same as constructors. Instead of using multiple lines, you use just one line to define them. Defining expression-bodied property accessors Property accessors can also benefit from the use of expression-bodied members. Here is a typical C# 6.0 property accessor with both get and set methods: private int _myVar; public MyVar { get { return _myVar; } set { SetProperty(ref _myVar, value); } } When working in C# 7.0, you can shorten the code using an expression-bodied member, like this: private int _myVar; public MyVar { get => _myVar; set => SetProperty(ref _myVar, value); } Defining expression-bodied event accessors As with property accessors, you can create an event accessor form using the expression-bodied member. Here’s what you might have used for C# 6.0: private EventHandler _myEvent; public event EventHandler MyEvent { add { _myEvent += value; } remove { _myEvent -= value; } } The expression-bodied member form of the same event accessor in C# 7.0 looks like this: private EventHandler _myEvent; public event EventHandler MyEvent { add => _myEvent += value; remove => _myEvent -= value; }

View Article
C# The C#-Provided Constructor

Article / Updated 01-31-2018

C# keeps track of whether a variable has been initialized and doesn’t allow you to use an uninitialized variable. For example, the following code chunk generates a compile-time error: public static void Main(string[] args) { int n; double d; double calculatedValue = n + d; } C# tracks the fact that the local variables n and d haven’t been assigned a value and doesn’t allow them to be used in the expression. Compiling this tiny program generates these compiler errors: Use of unassigned local variable 'n' Use of unassigned local variable 'd' By comparison, C# provides a default constructor that initializes the data members of an object to 0 for numbers false for Booleans null for object references Consider the following simple program example: using System; namespace Test { public class Program { public static void Main(string[] args) { // First create an object. MyObject localObject = new MyObject(); Console.WriteLine("localObject.n is {0}", localObject.n); if (localObject.nextObject == null) { Console.WriteLine("localObject.nextObject is null"); } // Wait for user to acknowledge the results. Console.WriteLine("Press Enter to terminate..."); Console.Read(); } } public class MyObject { internal int n; internal MyObject nextObject; } } This program defines a class MyObject, which contains both a simple data member n of type int and a reference to an object, nextObject (both declared internal). The Main() method creates a MyObject and then displays the initial contents of n and nextObject. The output from executing the program appears this way: localObject.n is 0 localObject.nextObject is null Press Enter to terminate... When the object is created, C# executes a small piece of code that the compiler provides to initialize the object and its members. Left to their own devices, the data members localObject.n and nextObject would contain random, garbage values. The code that initializes values when they’re created is the default constructor. It constructs the class, in the sense of initializing its members. Thus C# ensures that an object starts life in a known state: all zeros, nulls, or false values, depending on type. This concept affects only data members of the class, not local variables in a method.

View Article
page 1
page 2
page 3

Quick Links

  • About For Dummies
  • Contact Us
  • Activate Online Content

Connect

About Dummies

Dummies has always stood for taking on complex concepts and making them easy to understand. Dummies helps everyone be more knowledgeable and confident in applying what they know. Whether it's to pass that big test, qualify for that big promotion or even master that cooking technique; people who rely on dummies, rely on it to learn the critical skills and relevant information necessary for success.

Copyright @ 2000-2024 by John Wiley & Sons, Inc., or related companies. All rights reserved, including rights for text and data mining and training of artificial technologies or similar technologies.

Terms of Use
Privacy Policy
Cookies Settings
Do Not Sell My Personal Info - CA Only