I've got a two dimensional array containing the amount of sold articles with 6 different salesmen. I'm trying to sort the array to find the highest amount of sold articles of them all.
My problem is being able to sort the two dimensional array and to read its content.
I've tried
int[,] sortedByFirstElement = nrArticles.OrderBy(x => x[0]);
Which gives me an error message saying: "'int[,] does not contain a definition for 'OrderBy' and no accessible extension method... etc"
I've tried which gives me an error message claiming the input is not in int.
Array.Sort(nrArticles);
foreach (int value in nrArticles)
{
Console.Write(value);
}
The following code is what i've got so far excluding the sorting attempts.
string[,] salesMan = new string[6, 3];
int[,] nrArticles = new int[6, 0];
string line;
int nr;
for (int i = 0; i < 5; i++)
{
Console.Write("Enter the name of salesman: ");
line = Console.ReadLine();
salesMan[i, 0] = line;
Console.Write("Enter the social number: ");
line = Console.ReadLine();
salesMan[i, 1] = line;
Console.Write("Enter the district: ");
line = Console.ReadLine();
salesMan[i, 2] = line;
//This is where i convert the entered value into an int taken
by the array
Console.Write("Enter the amount of sold articles: ");
line = Console.ReadLine();
nr = Int32.Parse(line);
nrArticles[i, 0] = nr;
}
Console.Write("Namn \t\tPersnr \t\t\tDistrikt \t\tAntal");
for (int j = 0; j < 5; j++)
{
Console.Write("\n"+salesMan[j, 0] +"\t\t");
Console.Write(salesMan[j, 1] + "\t\t\t");
Console.Write(salesMan[j, 2] + "\t\t\t");
Console.Write(nrArticles[j, 0]);
}
//Here's where i'd put my code of sorting my integer array
nrArticles (If i had one).
}
}
The expected result of it would to see an example like: 231, 183, 130, 122, 40, 10. Maybe as a separate array, or even string?
Any help would be greatly appreciated.
Dictionary<int, List<int>>instead? You can useLINQwith that.