I have program in c#, that shows you highest number from 10 numbers you enter.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace Ole
{
class Program
{
static void Main(string[] args)
{
ArrayList list = new ArrayList();
for (int i = 0; i < 10; i++)
{
list.Add(Console.ReadLine());
}
list.Sort();
string Max = (string)list[list.Count - 1];
Console.WriteLine("{0}", Max);
Console.ReadLine();
}
}
}
But, command list.Sort() sorts it by only first digit, example:
24444
1212
2222
555
11
Will be sort like:
11
1212
2222
24444
555
How can I sort list by all digits to get "real" highest number?
Use a
List<int>
instead ofArrayList
, and parse the console input (string
) into a number (int
).See ArrayList vs List<> for why
List<T>
is used instead ofArrayList
now.