How to get items in order by min to max and move to temp list c#?
So i am trying to take a list of items and get it so that it is ordered by the min value first and so on. Then i wish to have it moved to a temporary list and check to see if the next item is equal to the previous by adding on and so forth. this is what i have done so far, but it is going from max to min, so i have it subtracting 1 instead of adding.
Loading

VulpesPosted May 4, 2011, 4:57 AM
using System;
using System.Collections.Generic;
class Test
{
static void Main()
{
var list = new List
list.Sort();
foreach(int i in list) Console.WriteLine(i); // displays in min to max order
Console.WriteLine();
var temp = new List
for(int i = 1; i < temp.Count; i++)
{
if (temp[i] == temp[i - 1] + 1)
{
Console.WriteLine("The elements at indices {0} and {1}, namely {2} and {3}, differ by 1", i - 1, i, temp[i-1], temp[i]);
}
}
Console.ReadKey();
}
}
FroglegPosted May 4, 2011, 12:09 AM