In C # - Linq: I have a collection of List of objects:
Field 1 | Field 2 | Field 3 | Field 4 | Field 5 | Test | 15 | 20 | 45 | 52 |
I need to transpose this row from a collection to a List of integers
15
20
45
52
Could anyone help?
I need a well-optimized version for this, without the burden of needing to iterate something.
Thank you.
To be clearer I will post the method in which I run my threads, it is precisely the foreach of the tens that I need to avoid:
public static void DoWork()
{
LFAcertos = new List<Lotofacil>();
var probabilidades = EnumerableExtentions.Combinations(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }, 15);
int acertos = 0;
int seqI = 0;
Int16 idMax = LotofacilService.GetMaxConcurso();
string info = string.Empty;
if (idMax < LFConcursos.Count)
{
for (Int16 i = idMax; i <= LFConcursos.Count; i++)
{
if (!idConEmUso.Contains(i) && !LotofacilService.ExistLotofacil(i))
{
info = string.Format("Lendo Concurso {0} em {1}", i, DateTime.Now);
Console.WriteLine(info);
log.Info(info);
idConEmUso.Add(i);
seqI = 0;
foreach (var seq in probabilidades)
{
seqI++;
acertos = 0;
foreach (int dezena in seq)
{
if (LFConcursos.Any(a => a.IdConcurso == i &&
(a.Bola1 == dezena ||
a.Bola2 == dezena ||
a.Bola3 == dezena ||
a.Bola4 == dezena ||
a.Bola5 == dezena ||
a.Bola6 == dezena ||
a.Bola7 == dezena ||
a.Bola8 == dezena ||
a.Bola9 == dezena ||
a.Bola10 == dezena ||
a.Bola11 == dezena ||
a.Bola12 == dezena ||
a.Bola13 == dezena ||
a.Bola14 == dezena ||
a.Bola15 == dezena
)))
{
acertos++;
}
}
if (acertos >= 14)
{
//info = string.Format("{0} acertos encontrados para o concurso {1} em {2}",acertos, i,DateTime.Now);
//Console.WriteLine(info);
//log.Info(info);
LotofacilService.SalvaLotofacil(new Lotofacil
{
IdConcurso = i,
IdSeqProb = seqI,
Bola1 = seq.Take(1).Single(),
Bola2 = seq.Take(2).Skip(1).Single(),
Bola3 = seq.Take(3).Skip(2).Single(),
Bola4 = seq.Take(4).Skip(3).Single(),
Bola5 = seq.Take(5).Skip(4).Single(),
Bola6 = seq.Take(6).Skip(5).Single(),
Bola7 = seq.Take(7).Skip(6).Single(),
Bola8 = seq.Take(8).Skip(7).Single(),
Bola9 = seq.Take(9).Skip(8).Single(),
Bola10 = seq.Take(10).Skip(9).Single(),
Bola11 = seq.Take(11).Skip(10).Single(),
Bola12 = seq.Take(12).Skip(11).Single(),
Bola13 = seq.Take(13).Skip(12).Single(),
Bola14 = seq.Take(14).Skip(13).Single(),
Bola15 = seq.Take(15).Skip(14).Single(),
Acertos = acertos
});
}
}
}
Thread.Sleep(2000);
}
}
}