Sure, you can solve this problem, as described at links from comments to your question, But, at this case, you should do tedious work - to write a lot of repeatable code like:
var answer = (from pos1 in list.Where(x => x.position == 1)
from pos2 in list.Where(x => x.position == 2)
from pos3 in list.Where(x => x.position == 3)
....
from pos10 in list.Where(x => x.position == 10)
select pos1.value + pos2.value + pos3.value + ... + pos10.value
).ToList();
So, each time, when you need to change number of possible positions you should add or remove corresponding lines of code. Instead, you can try recursive approach. Former solution is not dynamic - you should know number of positions in advance at compile time, whereas second solution can be simple tuned at run time via limit
variable changing.
static int limit = 10;
static void Recursive(record record, List<string> bag,
Stack<record> stack, List<record> list)
{
stack.Push(record);
if (record.position == limit)
{
var temp = new StringBuilder();
foreach (var item in stack)
temp.Insert(0, item.value);
bag.Add(temp.ToString());
}
else
foreach (var item in list.Where(x => x.position == record.position + 1))
Recursive(item, bag, stack, list);
stack.Pop();
}
static List<string> Solve(List<record> list)
{
for (var i = 1; i <= limit; i++)
if (!list.Any(x => x.position == i))
list.Add(new record { position = i, value = "." });
var bag = new List<string>();
var stack = new Stack<record>();
foreach (var record in list.Where(x => x.position == 1))
Recursive(record, bag, stack, list);
return bag;
}
Usage:
var list = new List<record>
{
new record { flashid = 450, position = 5, value = "a"},
new record { flashid = 450, position = 6, value = "b"},
new record { flashid = 450, position = 7, value = "c"},
new record { flashid = 450, position = 7, value = "d"},
new record { flashid = 450, position = 7, value = "e"},
new record { flashid = 450, position = 8, value = "f"},
new record { flashid = 450, position = 9, value = "g"}
};
var answer = Solve(list);
Console.WriteLine("[" + string.Join(", ", answer) + "]");
//output: [....abcfg., ....abdfg., ....abefg.]