{"id":62344,"date":"2022-01-13T05:52:27","date_gmt":"2022-01-13T04:52:27","guid":{"rendered":"https:\/\/drafts.code-maze.com\/?p=62291"},"modified":"2022-03-08T13:45:18","modified_gmt":"2022-03-08T12:45:18","slug":"csharp-selection-sort","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-selection-sort\/","title":{"rendered":"Selection Sort in C#"},"content":{"rendered":"<p>Sorting is one of the most common problems that programmers solve while building applications. Selection sort is one of the algorithms that we can use to sort elements in an array. We are going to learn how to implement selection sort in C# and analyze how the algorithm performs when sorting arrays of various sizes.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/csharp-algorithms\/SelectionSort\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s start.\u00a0<\/p>\n<h2><a id=\"what-is-selection-sort\"><\/a>What Is Selection Sort?<\/h2>\n<p>The goal of the selection sort algorithm is to find the minimum value of an array by iterating through each element. For each iteration, the algorithm compares the current minimum value of the array with the current element. If the current value is smaller than the minimum value, a swap process occurs. This process continues until the array is completely sorted.<\/p>\n<p>Let&#8217;s learn how selection sort in C# works and understand its time and space complexity.\u00a0<\/p>\n<h2><a id=\"algorithm\"><\/a>Selection Sort Algorithm In C#<\/h2>\n<p>Let&#8217;s assume we have an array of five numbers we need to sort in ascending order:<br \/>\n<code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">int[] array = { 40, 10, 20, 30, 50 };<\/code><\/p>\n<p>First, we find the minimum value from elements 0 to 4 (indexes) and place it at position 0. The minimum value is 10. Since 40 is currently on position 0 we are going to swap it with 10:<br \/>\n<code><span style=\"color: #ff0000;\">10<\/span>, <span style=\"color: #00ccff;\">40<\/span>, 20, 30, 50<\/code><\/p>\n<p>Then, we check the elements 1 through 4 and place the smallest value at position 1. In this case, 20 is the minimum and we swap it with 40:<br \/>\n<code>10, <span style=\"color: #ff0000;\">20<\/span>, <span style=\"color: #00ccff;\">40<\/span>, 30, 50<\/code><\/p>\n<p>Next, we check positions 2 through 4 and set the minimum value (30) to position 2:<br \/>\n<code>10, 20, <span style=\"color: #ff0000;\">30<\/span>, <span style=\"color: #00ccff;\">40<\/span>, 50<\/code><\/p>\n<p>Let&#8217;s learn how to implement Selection Sort in C#.\u00a0<\/p>\n<h2><a id=\"implementation\"><\/a>How to Implement Selection Sort in C#?<\/h2>\n<p>First, we are going to define an array property <code>NumArray<\/code> that we are going to use to implement selection sort:\u00a0<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public int[]? NumArray { get; set; }<\/code><\/p>\n<p>As the next step, we are going to create a <code>SortArray<\/code> method that iterates through the <code>NumArray<\/code> and sorts it in place:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public int[] SortArray()\r\n{\r\n    var arrayLength = NumArray.Length;\r\n\r\n    for (int i = 0; i &lt; arrayLength - 1; i++)\r\n    {\r\n        var smallestVal = i;\r\n\r\n        for (int j = i + 1; j &lt; arrayLength; j++)\r\n        {\r\n            if (NumArray[j] &lt; NumArray[smallestVal])\r\n            {\r\n                smallestVal = j;\r\n            }\r\n        }\r\n\r\n        var tempVar = NumArray[smallestVal];\r\n        NumArray[smallestVal] = NumArray[i];\r\n        NumArray[i] = tempVar;\r\n    }\r\n    return NumArray;\r\n}<\/pre>\n<p>We can see that the algorithm uses two nested loops during the sorting process. We define two variables\u00a0(<code>tempVar<\/code>\u00a0and <code>smallestVal<\/code>) that hold values during the sorting process.\u00a0As the outer loop iterates, <code>smallestVal<\/code> holds the current position of the array while the inner loop compares the current minimum value to the rest of the elements.\u00a0<\/p>\n<p>If the value of the array element is smaller than the current minimum value, swapping occurs. This process stops when the outer loop hits its <code>arrayLength<\/code> limit. \u00a0<\/p>\n<p>We can go ahead to verify that the method returns a sorted array:\u00a0<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var array = new int[] { 73, 57, 49, 99, 133, 20, 1 };\r\nvar expected = new int[] { 1, 20, 49, 57, 73, 99, 133 };\r\nvar sortFunction = new Selection();\r\nsortFunction.NumArray = array;\r\n\r\nvar sortedArray = sortFunction.SortArray();\r\n\r\nAssert.IsNotNull(sortedArray);\r\nCollectionAssert.AreEqual(sortedArray, expected);<\/pre>\n<h2><a id=\"time-complexity\"><\/a>Time and Space Complexity of Selection Sort<\/h2>\n<p>For each iteration, the smallest value and the current value swap their positions. To accomplish this, the algorithm uses nested loops to compare array elements.\u00a0<\/p>\n<p>As the length of the array increases to N, the time complexity would be O(N\u00b2) because we use two nested loops. The algorithm has a space complexity of O(1) as the sorting process doesn&#8217;t need an extra array to store the final result.\u00a0<\/p>\n<p><strong>Best Case Complexity:\u00a0<\/strong>it occurs when we need to sort a sorted array. The algorithm would need to perform comparisons without swapping values.\u00a0<\/p>\n<p><strong>Average Case Complexity: <\/strong>this scenario occurs when a mix of both sorted and unsorted values needs to be sorted in ascending order. The algorithm would need to perform comparisons while swapping some values.<\/p>\n<p><strong>Worst Case Complexity: <\/strong>assuming we have a list of numbers that are in descending order and we need to sort them in ascending order, the algorithm would encounter a worst-case complexity as the length of that array grows to N. Therefore, the algorithm compares while swapping all the values.<\/p>\n<h2><a id=\"when-to-use-selection-sort\"><\/a>Advantages of Using Selection Sort<\/h2>\n<p>Selection sort is ideal for <strong>sorting values that do not occupy a lot of memory<\/strong>. As the length of the array increases, the time taken to sort it increases exponentially as the algorithm has a time complexity of O(N\u00b2).\u00a0<\/p>\n<p>We can use this algorithm <strong>when the cost of swapping values doesn&#8217;t matter<\/strong>. For example, if the computing resources we need to swap those values are minimal, we could consider using this algorithm.<\/p>\n<p>Ideal for situations where the <strong>cost of writing to a disk space matters<\/strong>. For example, a flash disk with no extra space could work with this algorithm as opposed to a sorting algorithm such as <a href=\"https:\/\/code-maze.com\/csharp-bubble-sort\/\" target=\"_blank\" rel=\"nofollow noopener\">bubble sort<\/a> that has a space complexity of O(N\u00b2).<\/p>\n<h2><a id=\"when-not-to-use-selection-sort\"><\/a>Disadvantages of Using Selection Sort<\/h2>\n<p><strong>We should not use selection sort in a sorted array<\/strong>, as it would still perform O(N\u00b2) comparisons. In such a scenario, a sorting algorithm such as bubble sort would perform those comparisons in one iteration.<\/p>\n<p>Selection sort becomes inefficient as<strong> the size of the array grows<\/strong>. Using this algorithm in CPU-intensive applications could reduce their performance.\u00a0<\/p>\n<h2><a id=\"performance\"><\/a>Selection Sort Algorithm Performance in C#<\/h2>\n<p>Let&#8217;s verify that the selection sort algorithm has a time complexity of O(N\u00b2) by using performance benchmarks to test how long the algorithm takes to sort an array.<\/p>\n<p>To kickstart this process, we are going to define a method that generates random numbers and adds them to an array with a specific length:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static int[] AddRandomElements(int size)\r\n{\r\n    var array = new int[size];\r\n    var rand = new Random();\r\n    var maxNum = 10000;\r\n\r\n    for (int i = 0; i &lt; size; i++)\r\n        array[i] = rand.Next(maxNum + 1);\r\n\r\n    return array;\r\n}<\/pre>\n<p>The <code>AddRandomElements<\/code> method takes the length of the array as its input. Using the inbuilt <code>Random<\/code> class, we generate integer values (less than 10000) that we&#8217;re going to put into the array.<\/p>\n<p>To simulate a scenario where we have an array that is in order, we are going to define a method <code>AddSortedElements<\/code> that generates a sequence of elements:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static int[] AddSortedElements(int size)\r\n{\r\n    var array = new int[size];\r\n\r\n    for (int i = 0; i &lt; size; i++)\r\n        array[i] = i;\r\n\r\n    return array;\r\n}<\/pre>\n<p>Next, we are going to run a benchmark to understand how the algorithm performs when sorting arrays that have random elements:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">int[] smallArray = AddRandomElements(200);\r\nint[] mediumArray = AddRandomElements(2000);\r\nint[] largeArray = AddRandomElements(200000);<\/pre>\n<p>We define three array objects of different sizes (to simulate time complexity scenarios) that hold <a href=\"https:\/\/code-maze.com\/csharp-generate-random-numbers-range\/\" target=\"_blank\" rel=\"noopener\">random numbers<\/a> from the <code>AddRandomElements<\/code>\u00a0method. Let&#8217;s assess the sample best, average, and worst-case complexity performance results of the algorithm:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">|    Method |      NumArray |             Mean |            Error |           StdDev |\r\n|---------- |-------------- |-----------------:|-----------------:|-----------------:|\r\n| SortArray | Int32[200000] | 50,512,655.47 \u03bcs | 1,002,122.393 \u03bcs | 1,468,898.010 \u03bcs |\r\n| SortArray |   Int32[2000] |      3,843.17 \u03bcs |       187.741 \u03bcs |       553.558 \u03bcs |\r\n| SortArray |    Int32[200] |         40.56 \u03bcs |         1.775 \u03bcs |         5.232 \u03bcs |<\/pre>\n<p>We are going to assess whether the algorithm performs better when its attempts to sort arrays that are already in order than when it sorts arrays holding random elements. We invoke the <code>AddSortedElements<\/code> method when defining the array objects we are going to use for the next performance run:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">int[] sortedSmallArray = AddSortedElements(200);\r\nint[] sortedMediumArray = AddSortedElements(2000);\r\nint[] sortedLargeArray = AddSortedElements(200000);<\/pre>\n<p>Let&#8217;s see if there is any performance improvement in this run:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">|    Method |      NumArray |             Mean |            Error |           StdDev |\r\n|---------- |-------------- |-----------------:|-----------------:|-----------------:|\r\n| SortArray | Int32[200000] | 46,223,271.04 \u03bcs | 1,505,138.836 \u03bcs | 4,414,311.658 \u03bcs |\r\n| SortArray |   Int32[2000] |      3,565.99 \u03bcs |       132.440 \u03bcs |       390.502 \u03bcs |\r\n| SortArray |    Int32[200] |         38.67 \u03bcs |         1.746 \u03bcs |         5.149 \u03bcs |<\/pre>\n<p>Although selection sort performs slightly better when dealing with sorted arrays, it performs poorly when compared to other sorting algorithms such as merge sort. The benchmark shows that the best, average, and worst complexity of the selection sort implementation is O(N\u00b2).\u00a0<\/p>\n<h2><a id=\"conclusion\"><\/a>Conclusion<\/h2>\n<p>So, in this article, we&#8217;ve learned about the selection sort algorithm and its time and space complexity. We&#8217;ve covered how to implement the selection sort in C#, and also when should we use it and when not.\u00a0<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sorting is one of the most common problems that programmers solve while building applications. Selection sort is one of the algorithms that we can use to sort elements in an array. We are going to learn how to implement selection sort in C# and analyze how the algorithm performs when sorting arrays of various sizes. [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":62189,"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":[1010,12],"tags":[1140,1008,1142,1009,592,1141],"class_list":["post-62344","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-algorithm","category-csharp","tag-algorithm","tag-selection-sort","tag-selection-sort-algorithm","tag-selection-sorting","tag-sorting","tag-sorting-algorithm","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>Selection Sort in C# - Code Maze<\/title>\n<meta name=\"description\" content=\"In this article, we are going to talk about Selection Sort in C#, how to implement it, and when to use it and when not.\" \/>\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-selection-sort\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Selection Sort in C# - Code Maze\" \/>\n<meta property=\"og:description\" content=\"In this article, we are going to talk about Selection Sort in C#, how to implement it, and when to use it and when not.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-selection-sort\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-13T04:52:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-08T12:45:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.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=\"Code Maze\" \/>\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=\"Code Maze\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 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-selection-sort\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-selection-sort\/\"},\"author\":{\"name\":\"Code Maze\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\"},\"headline\":\"Selection Sort in C#\",\"datePublished\":\"2022-01-13T04:52:27+00:00\",\"dateModified\":\"2022-03-08T12:45:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-selection-sort\/\"},\"wordCount\":1081,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-selection-sort\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\"algorithm\",\"selection sort\",\"selection sort algorithm\",\"selection sorting\",\"sorting\",\"sorting algorithm\"],\"articleSection\":[\"Algorithm\",\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-selection-sort\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-selection-sort\/\",\"url\":\"https:\/\/code-maze.com\/csharp-selection-sort\/\",\"name\":\"Selection Sort in C# - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-selection-sort\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-selection-sort\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2022-01-13T04:52:27+00:00\",\"dateModified\":\"2022-03-08T12:45:18+00:00\",\"description\":\"In this article, we are going to talk about Selection Sort in C#, how to implement it, and when to use it and when not.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-selection-sort\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-selection-sort\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-selection-sort\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/csharp-selection-sort\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Selection Sort in C#\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04\",\"name\":\"Code Maze\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png\",\"caption\":\"Code Maze\"},\"description\":\"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/codemaze\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/codemazecontributor\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Selection Sort in C# - Code Maze","description":"In this article, we are going to talk about Selection Sort in C#, how to implement it, and when to use it and when not.","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-selection-sort\/","og_locale":"en_US","og_type":"article","og_title":"Selection Sort in C# - Code Maze","og_description":"In this article, we are going to talk about Selection Sort in C#, how to implement it, and when to use it and when not.","og_url":"https:\/\/code-maze.com\/csharp-selection-sort\/","og_site_name":"Code Maze","article_published_time":"2022-01-13T04:52:27+00:00","article_modified_time":"2022-03-08T12:45:18+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Code Maze","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Code Maze","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-selection-sort\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-selection-sort\/"},"author":{"name":"Code Maze","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04"},"headline":"Selection Sort in C#","datePublished":"2022-01-13T04:52:27+00:00","dateModified":"2022-03-08T12:45:18+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-selection-sort\/"},"wordCount":1081,"commentCount":0,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-selection-sort\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":["algorithm","selection sort","selection sort algorithm","selection sorting","sorting","sorting algorithm"],"articleSection":["Algorithm","C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-selection-sort\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-selection-sort\/","url":"https:\/\/code-maze.com\/csharp-selection-sort\/","name":"Selection Sort in C# - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-selection-sort\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-selection-sort\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2022-01-13T04:52:27+00:00","dateModified":"2022-03-08T12:45:18+00:00","description":"In this article, we are going to talk about Selection Sort in C#, how to implement it, and when to use it and when not.","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-selection-sort\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-selection-sort\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-selection-sort\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/csharp-selection-sort\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Selection Sort in C#"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/09d29b223012c8e94a68ba62861d0b04","name":"Code Maze","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez-150x150.png","caption":"Code Maze"},"description":"This is the standard author on the site. Most articles are published by individual authors, with their profiles, but when several authors have contributed, we publish collectively as a part of this profile.","sameAs":["https:\/\/www.linkedin.com\/company\/codemaze\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/codemazecontributor\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/62344","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\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=62344"}],"version-history":[{"count":6,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/62344\/revisions"}],"predecessor-version":[{"id":67488,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/62344\/revisions\/67488"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=62344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=62344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=62344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}