C# example- insertion sort algorithm

Insertion sort algorithm

This is C# example code for an insertion sort algorithm. If you are not sure about the process of the insertion sort, i recommend you to read:

Algorithm and Data Structure tutorial 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
class Program

static void Main(string[] args)
   int[] arr= new int[5]{23,2,3,34,6}; //unsorted data set
   insertsort(arr,5); //sorting process using insertion sort
   int i;
   Console.Write(arr[i]+"\t"); //after sorting


///insertion sort

static void insertsort(int[] dataset, int n){

int i,j;
   int pick_item=dataset[i];
   int inserted=0;
   for(j=i-1;j>=0 && inserted!=1;){
else inserted=1;


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.