Keep a dictionary with the string as key, and it's index as value, but only set the value if the key is not already in the dictionary.
Something like this might work for you;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Test {
public class Program {
public static void Main() {
var strings = new[] {"YYY", "XXX", "YYY", "ZZZ", "XXX", "ZZZ"};
var versionMap = new Dictionary<string, int>();
foreach (var s in strings) {
if (!versionMap.ContainsKey(s))
versionMap[s] = versionMap.Any() ? versionMap.Values.Max() + 1 : 1;
}
foreach (var s in strings)
Console.WriteLine("{0} : {1}", s, versionMap[s]);
}
}
}
Hope this helps,
Fredrik