{"id":4771,"date":"2018-10-26T08:20:35","date_gmt":"2018-10-26T06:20:35","guid":{"rendered":"https:\/\/code-maze.com\/?p=4771"},"modified":"2022-07-13T11:53:00","modified_gmt":"2022-07-13T09:53:00","slug":"csharp-generic-list-dictionary","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/","title":{"rendered":"C# Intermediate &#8211; Generic List and Dictionary"},"content":{"rendered":"<p>In this article, we are going to talk more about Generic List and Dictionary in C#. A <code>List&lt;T&gt;<\/code> and <code>Dictionary<\/code> are very useful collections in C#, and we are going to discover its features in the rest of the article.<\/p>\n<ul id=\"series_parts\" style=\"display: none;\">\n<li><a href=\"https:\/\/code-maze.com\/csharp-classes-constructors\/\" target=\"_blank\" rel=\"noopener noreferrer\">Classes and Constructors<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-properties\/\" target=\"_blank\" rel=\"noopener noreferrer\">Properties<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-static-members-constants-extension-methods\/\" target=\"_blank\" rel=\"noopener noreferrer\">Static Members, Constants, and Extension Methods<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-anonymous-nullable-types\/\" target=\"_blank\" rel=\"noopener noreferrer\">Anonymous and Nullable Types<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-structures\/\" target=\"_blank\" rel=\"noopener noreferrer\">Structures<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-enumerations\/\" target=\"_blank\" rel=\"noopener noreferrer\">Enumerations<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-inheritance\/\" target=\"_blank\" rel=\"noopener noreferrer\">Inheritance<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-interfaces\/\" target=\"_blank\" rel=\"noopener noreferrer\">Interfaces<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-abstract-classes\/\" target=\"_blank\" rel=\"noopener noreferrer\">Abstract Classes<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-generics\/\" target=\"_blank\" rel=\"noopener noreferrer\">Generics<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-queue-stack-hashtable\/\" target=\"_blank\" rel=\"noopener noreferrer\">Queue, Stack, Hashtable<\/a><\/li>\n<li>Generic List and Dictionary (Current article)<\/li>\n<li><a href=\"https:\/\/code-maze.com\/csharp-delegates\/\" target=\"_blank\" rel=\"noopener noreferrer\">Delegates<\/a><\/li>\n<\/ul>\n<div class=\"wrap-collabsible\">\r\n    <input id=\"collapsible\" class=\"toggle\" type=\"checkbox\">\r\n    <label for=\"collapsible\" class=\"lbl-toggle\" onclick=\"writeContent()\">This article is part of the series<\/label>\r\n    <div class=\"collapsible-content\">\r\n      <div class=\"content-inner\">\r\n        <p class=\"innerContent\" id=\"innerContent\"><\/p>\r\n        <script>\r\n           function writeContent(){\r\n               var links= document.getElementById(\"series_parts\").innerHTML;\r\n               document.getElementById(\"innerContent\").innerHTML = links;\r\n           }\r\n       <\/script>\r\n      <\/div>\r\n    <\/div>\r\n<\/div>\r\n\n<p>If you want to see complete navigation of this tutorial, you can do that here <a href=\"https:\/\/code-maze.com\/csharp-intermediate-tutorial-oop\/\" target=\"_blank\" rel=\"noopener noreferrer\">C# Intermediate Tutorial.<\/a><\/p>\n<p>To download the source code, you can visit <a href=\"https:\/\/github.com\/CodeMazeBlog\/csharp-intermediate-module\/tree\/list-dictionary\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">the Generic List and Dictionary in C# Source Code.\u00a0<\/a><\/p>\n<p>We are going to split this article into the following sections:<\/p>\n<ul>\n<li><a href=\"#list\">List&lt;T&gt;<\/a><\/li>\n<li><a href=\"#listmethods\">Methods and Properties<\/a><\/li>\n<li><a href=\"#dictionary\">Dictionary<\/a><\/li>\n<li><a href=\"#dictionarymethods\">Methods and Properties<\/a><\/li>\n<\/ul>\n<h2 id=\"list\"><span lang=\"EN-US\">List&lt;T&gt;<\/span><\/h2>\n<p>A <code>List&lt;T&gt;<\/code> represents a strongly typed collection of objects that can be accessed by index.<\/p>\n<p>To instantiate a <code>List&lt;T&gt;<\/code> we need to provide a type between the angle brackets:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">List&lt;int&gt; numberList = new List&lt;int&gt;();\r\nList&lt;Student&gt; students = new List&lt;Student&gt;();\r\n<\/pre>\n<p>It has two more constructors that we can use to initialize a List object. With the first one, we can set initial capacity:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">List&lt;int&gt; numbers = new List&lt;int&gt;(2);<\/pre>\n<p>With the second one, we can populate our list with the IEnumerable collection:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">int[] nums = new int[5] { 1, 2, 3, 4, 5 };\r\nList&lt;int&gt; numbers = new List&lt;int&gt;(nums);\r\n<\/pre>\n<p>To access any element we can specify its index position:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">int number = numbers[1];<\/pre>\n<h2 id=\"listmethods\"><span lang=\"EN-US\">Methods and Properties<\/span><\/h2>\n<p>The <code>Add<\/code> method adds the element inside a list:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">List&lt;int&gt; numbers = new List&lt;int&gt;();\r\nnumbers.Add(34);\r\nnumbers.Add(58);\r\nnumbers.Add(69);\r\n\r\nforeach (int number in numbers)\r\n{\r\n    Console.WriteLine(number);\r\n}\r\n<\/pre>\n<p><code>AddRange<\/code>\u00a0adds the elements of the specified collection to the end of a list:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">List&lt;int&gt; numbers = new List&lt;int&gt;();\r\nnumbers.Add(34);\r\nnumbers.Add(58);\r\nnumbers.Add(69);\r\n\r\nint[] nums = new int[] { 1, 22, 44 };\r\n\r\nnumbers.AddRange(nums);\r\n\r\nforeach (int number in numbers)\r\n{\r\n     Console.WriteLine(number);\r\n}\r\n<\/pre>\n<p><code>Contains<\/code>\u00a0determines whether an element exists in the list:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">if(numbers.Contains(34))\r\n{\r\n     Console.WriteLine(\"The number 34 exists in a list\");\r\n}\r\n<\/pre>\n<p>The <code>IndexOf<\/code> method returns the position of an element as an integer number. If an element couldn\u2019t be found, this method returns -1:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">int index;\r\nif((index = numbers.IndexOf(58)) != -1)\r\n{\r\n    Console.WriteLine($\"The number 58 is on the index: {index}\");\r\n}\r\n<\/pre>\n<p><code>LastIndexOf<\/code> is similar to a previous method except it returns a last occurrence of the element.<\/p>\n<p><code>CopyTo<\/code> method copies the entire collection to a compatible array, starting from the beginning of that array:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">int[] copyArray = new int[6];\r\n\r\nnumbers.CopyTo(copyArray);\r\n\r\nforeach (int copyNumber in copyArray)\r\n{\r\n     Console.WriteLine(copyNumber);\r\n}\r\n<\/pre>\n<p>The <code>Remove<\/code> method removes the first occurrence of a specific element from the list:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">numbers.Remove(69);<\/pre>\n<p>The Clear method clears all the elements from a list:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">numbers.Clear();<\/pre>\n<p>We can check how many elements a list has by using the <code>Count<\/code> property:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Console.WriteLine(numbers.Count);<\/pre>\n<h2 id=\"dictionary\"><span lang=\"EN-US\">Dictionary<\/span><\/h2>\n<p><code>Dictionary<\/code> represents a collection of keys and values. To instantiate an object we can use the following syntax:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Dictionary&lt;KeyType, ValueType&gt; Name = new Dictionary&lt;KeyType, ValueType&gt;();<\/pre>\n<p>The KeyType represents a type for our key in a collection. The ValueType represents the value assigned to the key. So, we can extract our value from a collection by using the key inside the square brackets:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">DictionaryName[key];<\/pre>\n<p>Dictionary has several constructors we can use to instantiate objects:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Dictionary&lt;string, int&gt; dictExample = new Dictionary&lt;string, int&gt;();\r\n\r\nDictionary&lt;string, int&gt; dictExample1 = new Dictionary&lt;string, int&gt;(5); \/\/to set initial size\r\n\r\nDictionary&lt;string, int&gt; dictExample2 = new Dictionary&lt;string, int&gt;(dictExample1); \/\/accepts all the elements from created Key-Value collection\r\n<\/pre>\n<h2 id=\"dictionarymethods\"><span lang=\"EN-US\">Methods and Properties<\/span><\/h2>\n<p>The <code>Add<\/code> method adds the key-value pair inside a collection:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Dictionary&lt;string, int&gt; dictExample = new Dictionary&lt;string, int&gt;();\r\n\r\ndictExample.Add(\"First\", 100);\r\ndictExample.Add(\"Second\", 200);\r\ndictExample.Add(\"Third\", 300);\r\n\r\nforeach (var item in dictExample)\r\n{\r\n     Console.WriteLine(dictExample[item.Key]);\r\n}\r\n<\/pre>\n<p><code>Remove<\/code> removes the key-value pair from a collection based on the specified key:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">dictExample.Remove(\"Second\");\r\nforeach (var item in dictExample)\r\n{\r\n     Console.WriteLine(dictExample[item.Key]);\r\n}\r\n<\/pre>\n<p><code>ContainsKey<\/code>\u00a0determines if a collection contains a specific key.<\/p>\n<p><code>ContainsValue<\/code>\u00a0determines if a collection contains a specific value:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">if(dictExample.ContainsKey(\"First\"))\r\n{\r\n     Console.WriteLine(\"It contains key\");\r\n}\r\n\r\nif(dictExample.ContainsValue(300))\r\n{\r\n      Console.WriteLine(\"It contains value\");\r\n}\r\n<\/pre>\n<p>The <code>Clear<\/code> method removes all key-value pairs from a collection:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">dictExample.Clear();<\/pre>\n<p>If we want to count all of our elements inside a collection, we can use the <code>Count<\/code> property. If we want to get a collection of containing <code>Keys<\/code> or containing <code>Values<\/code> from a dictionary, we can use the <code>Keys<\/code> and <code>Values<\/code> properties:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Console.WriteLine(dictExample.Count);\r\n\r\nforeach (var key in dictExample.Keys)\r\n{\r\n     Console.WriteLine(key);\r\n}\r\n\r\nforeach (var value in dictExample.Values)\r\n{\r\n     Console.WriteLine(value);\r\n}\r\n<\/pre>\n<h2>Conclusion<\/h2>\n<p>In this article, we have learned:<\/p>\n<ul>\n<li>To use the List&lt;T&gt; collection with its methods<\/li>\n<li>To use a Dictionary with its methods and properties<\/li>\n<\/ul>\n<p>In the next article, we are going to talk about <a href=\"https:\/\/code-maze.com\/csharp-delegates\/\" target=\"_blank\" rel=\"noopener noreferrer\">Delegates in C#<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we are going to talk more about Generic List and Dictionary in C#. A List&lt;T&gt; and Dictionary are very useful collections in C#, and we are going to discover its features in the rest of the article. Classes and Constructors Properties Static Members, Constants, and Extension Methods Anonymous and Nullable Types Structures [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":54505,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12,506],"tags":[379,946,381,380,378,377,247,248,376,245],"class_list":["post-4771","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","category-intermediate","tag-add","tag-collections","tag-contains","tag-copyto","tag-dictionary","tag-generic-list","tag-indexof","tag-lastindexof","tag-list","tag-remove","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C# Intermediate - Generic List and Dictionary - Code Maze<\/title>\n<meta name=\"description\" content=\"In this article, you will learn about Generic List and Dictionary in C#. You will learn how lists work, how we can use tham and how to use key value pairs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C# Intermediate - Generic List and Dictionary - Code Maze\" \/>\n<meta property=\"og:description\" content=\"In this article, you will learn about Generic List and Dictionary in C#. You will learn how lists work, how we can use tham and how to use key value pairs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2018-10-26T06:20:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-13T09:53:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/10\/12-Generic-List-and-Dictionary.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Marinko Spasojevi\u0107\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Marinko Spasojevi\u0107\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/\"},\"author\":{\"name\":\"Marinko Spasojevi\u0107\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533\"},\"headline\":\"C# Intermediate &#8211; Generic List and Dictionary\",\"datePublished\":\"2018-10-26T06:20:35+00:00\",\"dateModified\":\"2022-07-13T09:53:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/\"},\"wordCount\":536,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/10\/12-Generic-List-and-Dictionary.png\",\"keywords\":[\"Add\",\"collections\",\"Contains\",\"CopyTo\",\"dictionary\",\"generic list\",\"IndexOf\",\"LastIndexOf\",\"list\",\"Remove\"],\"articleSection\":[\"C#\",\"Intermediate\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/\",\"url\":\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/\",\"name\":\"C# Intermediate - Generic List and Dictionary - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/10\/12-Generic-List-and-Dictionary.png\",\"datePublished\":\"2018-10-26T06:20:35+00:00\",\"dateModified\":\"2022-07-13T09:53:00+00:00\",\"description\":\"In this article, you will learn about Generic List and Dictionary in C#. You will learn how lists work, how we can use tham and how to use key value pairs.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/10\/12-Generic-List-and-Dictionary.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/10\/12-Generic-List-and-Dictionary.png\",\"width\":1100,\"height\":620,\"caption\":\"12 Generic List and Dictionary\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C# Intermediate &#8211; Generic List and Dictionary\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533\",\"name\":\"Marinko Spasojevi\u0107\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg\",\"caption\":\"Marinko Spasojevi\u0107\"},\"description\":\"Hi, my name is Marinko Spasojevic. Currently, I work as a full-time .NET developer and my passion is web application development. Just getting something to work is not enough for me. To make it just how I like it, it must be readable, reusable, and easy to maintain. Prior to being an author on the CodeMaze blog, I had been working as a professor of Computer Science for several years. So, sharing knowledge while working as a full-time developer comes naturally to me.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/marinko-spasojevic\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/marinko\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C# Intermediate - Generic List and Dictionary - Code Maze","description":"In this article, you will learn about Generic List and Dictionary in C#. You will learn how lists work, how we can use tham and how to use key value pairs.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/","og_locale":"en_US","og_type":"article","og_title":"C# Intermediate - Generic List and Dictionary - Code Maze","og_description":"In this article, you will learn about Generic List and Dictionary in C#. You will learn how lists work, how we can use tham and how to use key value pairs.","og_url":"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/","og_site_name":"Code Maze","article_published_time":"2018-10-26T06:20:35+00:00","article_modified_time":"2022-07-13T09:53:00+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/10\/12-Generic-List-and-Dictionary.png","type":"image\/png"}],"author":"Marinko Spasojevi\u0107","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Marinko Spasojevi\u0107","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/"},"author":{"name":"Marinko Spasojevi\u0107","@id":"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533"},"headline":"C# Intermediate &#8211; Generic List and Dictionary","datePublished":"2018-10-26T06:20:35+00:00","dateModified":"2022-07-13T09:53:00+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/"},"wordCount":536,"commentCount":0,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/10\/12-Generic-List-and-Dictionary.png","keywords":["Add","collections","Contains","CopyTo","dictionary","generic list","IndexOf","LastIndexOf","list","Remove"],"articleSection":["C#","Intermediate"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/","url":"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/","name":"C# Intermediate - Generic List and Dictionary - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/10\/12-Generic-List-and-Dictionary.png","datePublished":"2018-10-26T06:20:35+00:00","dateModified":"2022-07-13T09:53:00+00:00","description":"In this article, you will learn about Generic List and Dictionary in C#. You will learn how lists work, how we can use tham and how to use key value pairs.","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-generic-list-dictionary\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/10\/12-Generic-List-and-Dictionary.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/10\/12-Generic-List-and-Dictionary.png","width":1100,"height":620,"caption":"12 Generic List and Dictionary"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/csharp-generic-list-dictionary\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"C# Intermediate &#8211; Generic List and Dictionary"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533","name":"Marinko Spasojevi\u0107","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg","caption":"Marinko Spasojevi\u0107"},"description":"Hi, my name is Marinko Spasojevic. Currently, I work as a full-time .NET developer and my passion is web application development. Just getting something to work is not enough for me. To make it just how I like it, it must be readable, reusable, and easy to maintain. Prior to being an author on the CodeMaze blog, I had been working as a professor of Computer Science for several years. So, sharing knowledge while working as a full-time developer comes naturally to me.","sameAs":["https:\/\/www.linkedin.com\/in\/marinko-spasojevic\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/marinko\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/4771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=4771"}],"version-history":[{"count":1,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/4771\/revisions"}],"predecessor-version":[{"id":72467,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/4771\/revisions\/72467"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/54505"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=4771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=4771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=4771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}