Since you have a range of 0-100
and you just have A
and B
as a prefix, We populate two lists each with ints
from 0 to 100
and then use System.Linq
to find all combinations and append then to a list
with a delimiter. Now just replace the delimiter.
There are a bunch of ways you can go about it, I would recommend using System.Linq
public static IEnumerable<string> FindAllCombinationsAnotherWay()
{
List<int> ListOne = Enumerable.Range(1, 100).ToList();
List<int> ListTwo = Enumerable.Range(1, 100).ToList();
var result = ListOne.SelectMany((a, indexA) =>
ListTwo.Where((b, indexB) =>
ListTwo.Contains(a) ? !b.Equals(a) && indexB > indexA
: !b.Equals(a))
.Select(b => string.Format("A{0:00}B{1:00}", a, b)));
return result.Distinct();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…