Hi ravikhoda,
Good Problem to use LINQ:
Here is a Little sample program
using System;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] aNumbers = { 1, 1, 2, 2, 3, 4, 5, 6, 6, 7 };
var indices = from number in aNumbers.Distinct()
select aNumbers.ToList().LastIndexOf(number);
int[] aIndices = indices.ToArray();
foreach (int iIndex in aIndices)
Console.WriteLine(iIndex);
Console.ReadKey();
}
}
}
The idea is to select only the distinct values from the original array. Then we call
LastIndexOf
for every distinct number on the original array. By this expression we build a IEnumerable of our indices. This is converted to your desired array of integers output-type (would not be needed just for enumerating like in the above sample).
Hope this helps
Kind regards Johannes