How to rewrite the below code in a better way as to give the best performance
private static void GetCount(int No, int[,] Positions)
{
List<int> lstRows = new List<int>();
List<int> lstCols = new List<int>();
int count = 0;
//Get the unique rows and columns
for (int i = 0; i < Positions.Length / 2; i++)
{
if (!lstRows.Contains(Positions[i, 0])) lstRows.Add(Positions[i, 0]);
if (!lstCols.Contains(Positions[i, 1])) lstCols.Add(Positions[i, 1]);
}
//get row count
for (int i = 0; i < lstRows.Count; i++) count += 8;
//get column count
for (int i = 0; i < lstCols.Count; i++) count += 8;
int output = No-count;
Console.WriteLine(output);
}
Invocation as GetCount(1, new int[,] { { 6, 3 } });
How about this one:
if you don’t want to use loop and want to do it using pure lambda and linq(just for less code, not for performance):