{"id":120243,"date":"2020-11-25T16:00:50","date_gmt":"2020-11-25T13:00:50","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/8-awesome-c-features-you-should-know-about-cloudsavvy-it\/"},"modified":"2020-11-25T16:00:50","modified_gmt":"2020-11-25T13:00:50","slug":"8-awesome-c-features-you-should-know-about-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/8-awesome-c-features-you-should-know-about-cloudsavvy-it\/","title":{"rendered":"#8 Awesome C# Features You Should Know About \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2a39d3b7a0f\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2a39d3b7a0f\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/8-awesome-c-features-you-should-know-about-cloudsavvy-it\/#Nullable_Reference_Types\" >Nullable Reference Types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/8-awesome-c-features-you-should-know-about-cloudsavvy-it\/#Null-Conditional_and_Null_Coalescing_Operators\" >Null-Conditional and Null Coalescing Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/8-awesome-c-features-you-should-know-about-cloudsavvy-it\/#Tuples\" >Tuples<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/8-awesome-c-features-you-should-know-about-cloudsavvy-it\/#Constructor_Overloading_With_this\" >Constructor Overloading With : this ()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/8-awesome-c-features-you-should-know-about-cloudsavvy-it\/#Static_Constructors\" >Static Constructors<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/buradabiliyorum.com\/en\/8-awesome-c-features-you-should-know-about-cloudsavvy-it\/#Generic_Type_Parameters\" >Generic Type Parameters<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/buradabiliyorum.com\/en\/8-awesome-c-features-you-should-know-about-cloudsavvy-it\/#Delegates\" >Delegates<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/buradabiliyorum.com\/en\/8-awesome-c-features-you-should-know-about-cloudsavvy-it\/#Indexers\" >Indexers<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#8 Awesome C# Features You Should Know About \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6018\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/d9bee69b242da6fb57907d0799a9fdf4\/p\/uploads\/2020\/08\/b476fc9b.png\" alt=\"\" width=\"700\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>C# and .NET have both been in consistent active development for the last two decades; every year the language gets a set of new useful features. We\u2019ll discuss some of our favorites that we think beginners should know about.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Nullable_Reference_Types\"><\/span>Nullable Reference Types<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>C# has had nullable\u00a0<em>value<\/em> types for a while, such as \u201d\u00a0<code>int?<\/code>\u00a0\u201d which can hold either an <code>int<\/code>\u00a0or the value of <code>null<\/code>, as opposed to a traditional <code>int<\/code>\u00a0which would always have a default value of zero. These are useful for a lot of things, including classes meant for JSON deserialization, where not all fields may be present.<\/p>\n<p>However, reference types have always been able to be assigned a <code>null<\/code>\u00a0value, so what\u2019s the point of this new feature from C# 8.0?<\/p>\n<p>Nullable reference types basically enforce a distinction between reference variables that can go null, and reference variables that can\u2019t. It\u2019s a breaking feature that will likely leave your codebase with a lot of warnings, so it\u2019s something you have to manually turn on. Once it\u2019s on, the compiler start to tell the difference between:<\/p>\n<ul>\n<li><code>string?<\/code>, which can be null, and retains the \u201cdefault\u201d behavior from earlier versions, and<\/li>\n<li><code>string<\/code>, which\u00a0<em>cannot<\/em>\u00a0be null. It can never be null, because it must be given a default value, and can never be set to null.<\/li>\n<\/ul>\n<p>This has a lot of interesting effects, but the most important one is an implicit focus on proper\u00a0<code>null<\/code>\u00a0value handling at a language level. For example, The compiler will yell at you if you try to return a null value for a function that returns a non-nullable value. It will also yell at you if you try to pass a possibly null value into a function that isn\u2019t expecting it.<\/p>\n<p>While that can sound restricting, much like static typing it leads to better and more usable code in the end. We highly recommend enabling it for most projects, and you can read our full guide on them to learn more.<\/p>\n<p>To turn it on, you\u2019ll need to edit your project file. In Visual Studio, right click on your project and click \u201cEdit Project File.\u201d Then turn it on with the following directive:<\/p>\n<pre>&lt;Nullable&gt;enable&lt;\/Nullable&gt;<\/pre>\n<p>If you are using the legacy project format, you might need to manually override this with a directive at the top of each file:<\/p>\n<pre>#nullable enable<\/pre>\n<p><strong>RELATED:<\/strong> <strong><em>How Do C#&#8217;s Nullable Reference Types Work?<\/em><\/strong><\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Null-Conditional_and_Null_Coalescing_Operators\"><\/span>Null-Conditional and Null Coalescing Operators<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Rather than having to check <code>if(something == null)<\/code>, C# has an awesome shorthand with\u00a0<a rel=\"nofollow noopener noreferrer\" target=\"_blank\" href=\"http:\/\/redirect.viglink.com?u=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fcsharp%2Flanguage-reference%2Foperators%2Fmember-access-operators%23null-conditional-operators--and-&amp;key=204a528a336ede4177fff0d84a044482\">null-conditional member access operators<\/a>. Basically, rather than using a period to access something that may be null, you can use a question mark and a period, which will perform the null check automatically.<\/p>\n<p>You can also use these for calling methods on null objects, or accessing indexes on null arrays. If the object ends up being null, it simply does nothing, and returns a null value.<\/p>\n<pre>reference?.field&#13;\nreference?.method();&#13;\nreference?[N]<\/pre>\n<p>Note that the last one does not prevent an IndexOutOfRangeException\u2014it simply accesses the Nth element of a possibly null list.<\/p>\n<p>However, you may have to work with the null values returned by this expression, and to make that easier C# has <a rel=\"nofollow noopener noreferrer\" target=\"_blank\" href=\"http:\/\/redirect.viglink.com?u=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fcsharp%2Flanguage-reference%2Foperators%2Fnull-coalescing-operator&amp;key=204a528a336ede4177fff0d84a044482\">null-coalescing operators<\/a>. These can be used to assign an alternative value in the event that an expression (any expression) returns a null value. Essentially, they\u2019re backup values. You can specify them with double question marks:<\/p>\n<pre>string value = GetValue() ?? \"Backup\"<\/pre>\n<p>There is also the <code>??=<\/code>\u00a0operator, which functions like <code>||<\/code>\u00a0in that it won\u2019t evaluate the backup value if the first value returns a proper result.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Tuples\"><\/span>Tuples<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Ever wanted to return multiple values from a method? With tuples you can, and modern C# has had great language support for them since\u00a0C# 7.0. Simply return two values surrounded by parentheses and separated by commas, and you can access the individual items within them.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8075\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/2113fffc123541dabbb215f06461834f\/p\/uploads\/2020\/11\/cf0b2ee6.png\" alt=\"\" width=\"419\" height=\"250\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>While it\u2019s not required, it is common practice to give these names, such as <code> (float X, float Y, float Z)<\/code>, rather than accessing them by item numbers.<\/p>\n<p>You can also use tuple deconstruction to dissemble a tuple into multiple component variables.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8076\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/7fac8cbfe5f5987c9474139bab5b4398\/p\/uploads\/2020\/11\/ee32f8a7.png\" alt=\"\" width=\"366\" height=\"103\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>This is actually quite useful for simple constructors, where you need to set a few fields equal to input arguments. Using tuple deconstruction accomplishes this pretty cleanly:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8074\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/5e047765b9e34d4df9dd3f299276c733\/p\/uploads\/2020\/11\/7f870c99.png\" alt=\"\" width=\"473\" height=\"213\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Constructor_Overloading_With_this\"><\/span>Constructor Overloading With : this ()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Constructors, like any other method, can be operator overloaded to support many different combinations of parameters. However, since constructors are commonly used to initialize many fields, this can lead to code duplication.<\/p>\n<p>A quick and dirty fix would be to share a \u201cinitialize class\u201d method that\u2019s called from all overloaded constructor methods, but if you have nullable reference types enabled, you\u2019ll get nullability warnings for non-nullable fields that are actually getting set, since the compiler isn\u2019t smart enough to understand initialization in impure function calls.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8013\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/a46eb51f1241409e7242f27cb12caf97\/p\/uploads\/2020\/11\/7d9a4a83.png\" alt=\"\" width=\"641\" height=\"308\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>But, there is fix for this, and it\u2019s a little weird. It comes from\u00a0<em>constructor inheritance<\/em>, which is another awesome feature that allows you to expand upon the constructor of the base class. It uses the same inheritance syntax, a colon, followed by <code>base (parameters)<\/code>. This will automatically call the base constructor (before the new one). Note that you still need to put the base constructor\u2019s parameters in the method definition.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8011\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/e9b4298988d3e062fe1f6065a17fb2a6\/p\/uploads\/2020\/11\/76f3488e.png\" alt=\"\" width=\"527\" height=\"284\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>The cool part is that you don\u2019t need to use <code>base<\/code>; you can actually do the exact same thing with <code>: this ()<\/code>, which will call a constructor within the class itself. You can use this to specify additional parameters without copying initialization code.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8014\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/7c2ccf8e50166616136e08ceceeb145e\/p\/uploads\/2020\/11\/2ea0b296.png\" alt=\"\" width=\"700\" height=\"299\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You\u2019ll obviously need to declare the optional fields as nullable, since they are as the base constructor does not support them. But that\u2019s by design here; in this example, the person\u2019s first and last name needs to be set, but the email may or may not be, making it suitable for a nullable type.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Static_Constructors\"><\/span>Static Constructors<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Constructors are commonly used to create instances of classes using the <code>new<\/code>\u00a0keyword. In the constructor, you can set up the fields required to initialize the class.<\/p>\n<p>But what about static classes? Well, they actually can use constructors as well. In fact, regular classes can use static constructors to set up their static properties.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8072\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/9689da32c999b5d8ea736c7c7b63ce8b\/p\/uploads\/2020\/11\/376bb28e.png\" alt=\"\" width=\"361\" height=\"184\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>However, these don\u2019t exactly run at startup. While the above example looks correct, setting the <code>startupTime<\/code>\u00a0in a static constructor, it\u2019s not guaranteed at runtime because C#, and the MSIL it runs on, is a Just-In-Time compiled language.<\/p>\n<p>JIT compilation only occurs, well, just in time, exactly when the class is needed. This means that the class will sit off in its corner of the assembly, collecting dust until one of its fields or methods are needed. Once it\u2019s needed, the .NET runtime will dust it off, compile it up, and only then invoke the static constructor.<\/p>\n<p>However, the static constructor still runs before\u00a0<em>anything<\/em>, even before static fields are set up, and before anything can be referenced. They\u2019re still quite useful when you need them. Alternatively, you can call an initialization method from your <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>lication\u2019s startup routine if you need to run something in chronological order.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Generic_Type_Parameters\"><\/span>Generic Type Parameters<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You\u2019ve definitely run into these before, though you may not have written one yourself. Generic type parameters allow you to write functions that are type-agnostic, and don\u2019t care about the type being passed to it. The primary example of this is collections; a <code>List&lt;string&gt;<\/code>\u00a0and a <code>List&lt;int&gt;<\/code>\u00a0use the same code, but are passed a different generic type parameter.<\/p>\n<p>Generics are pretty easy to use yourself. Simply add a name for the type variable in brackets in the class or method definition. It\u2019s common practice to use T, or at least names that start with T. For example, a dictionary might have TKey and TValue, two different types.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-6502 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/89b7d18d52555603f9d1a2fcea786f2c\/p\/uploads\/2020\/08\/9ef85b7c.png\" alt=\"Pass type parameters using &lt;T&gt;\u00a0bracket syntax.\" width=\"458\" height=\"350\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can use them in functions too, and if you use the type parameter as an argument type, it can even be inferred automatically.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-6508 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/5012d8c185b8fe1f4fa90c913778f22f\/p\/uploads\/2020\/08\/fbd0b057.png\" alt=\"Use type parameter in the actual parameters of the function\" width=\"574\" height=\"124\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Generic types create multiple different \u201ctypes\u201d of the generic class. This means static fields will be separate based on the type of the class, so <code>List&lt;string&gt;<\/code>\u00a0shares no data with <code>List&lt;int&gt;<\/code>.<\/p>\n<p>Because of this, you need to pass it a type parameter if you want to reference the class name directly. This can be a problem in some cases, so alternatively, if you need to support multiple types, you <a rel=\"nofollow noopener noreferrer\" target=\"_blank\" href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/programming-guide\/types\/boxing-and-unboxing\">can cast to and from <code>object<\/code>\u00a0using a technique called boxing<\/a>.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Delegates\"><\/span>Delegates<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Delegates are a way of packaging methods into variables. This is useful for dependency injection, which is a overly fancy name for a simple concept\u2014flexible classes should get some values, called dependencies, from their constructor variables, allowing the user of that class to specify the dependencies at will.<\/p>\n<p>Delegates allow you to do this with functions. You can have the class take any kind of action, and it doesn\u2019t care about the implementation. These are still statically typed\u2014you will have to define the input and output parameters like you would with any function, except mark it with \u201cdelegate\u201d and don\u2019t write a body.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-6410 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/a19a084b2abfdb7cb3304b93356d9c73\/p\/uploads\/2020\/08\/34a3e6c6.png\" alt=\"An implementation with code.\" width=\"455\" height=\"149\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can then assign a function to this variable, and then use the\u00a0<em>variable<\/em> to invoke the function. You can do this directly like shown, or you can use <code>myDelegate.Invoke()<\/code>, which does the same thing but more verbose.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-6411 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/ddf0a0730cb75f30d63e7aa5c026626e\/p\/uploads\/2020\/08\/77de25cb.png\" alt=\"The .NET runtime looks at what method the delegate points to and invokes it.\" width=\"487\" height=\"127\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can read more about delegates in our guide to using them.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Indexers\"><\/span>Indexers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Classes in C# use fields to store data, and properties to expose that data to other classes. Properties are really just a method exposing a field so that you can access it by doing <code>class.property<\/code>.<\/p>\n<p>You can do the same thing for indexing, e.g. <code>class[index]<\/code>. This can be used to create custom indexing behaviour. For example, you can create a 2D list from a 1D <code>List&lt;T&gt;<\/code> by making a custom indexer that returns a value based on the input arguments.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8169\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/d5df5e4c779c559a50c0e0700ba08e56\/p\/uploads\/2020\/11\/e2794708.png\" alt=\"\" width=\"443\" height=\"139\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/>\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener noreferrer\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/8007\/8-awesome-c-features-you-should-know-about\/\" target=\"_blank\" rel=\"noopener noreferrer\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#8 Awesome C# Features You Should Know About \u2013 CloudSavvy IT&#8221; C# and .NET have both been in consistent active development for the last two decades; every year the language gets a set of new useful features. We\u2019ll discuss some of our favorites that we think beginners should know about. Nullable Reference Types C# has&#8230;<\/p>\n","protected":false},"author":1,"featured_media":120244,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/08\/b476fc9b.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-120243","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/120243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=120243"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/120243\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/120244"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=120243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=120243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=120243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}