176 messaggi dal 13 febbraio 2004
sto muovendo i primi passi con LINQ,

PEr poter selezionare un singolo valore di un object List, come posso fare?


public class ConvLotto
{
public string Day { get; set; }
public string TDay { get; set; }

}

List<ConvLotto> convLotto = new List<ConvLotto>
{
new ConvLotto{Day="1",TDay="C"},
new ConvLotto{Day="2",TDay="5"},
new ConvLotto{Day="3",TDay="T"},
new ConvLotto{Day="4",TDay="2"},
new ConvLotto{Day="5",TDay="S"},
new ConvLotto{Day="6",TDay="3"},
new ConvLotto{Day="7",TDay="B"},
new ConvLotto{Day="8",TDay="1"},
new ConvLotto{Day="9",TDay="A"},
new ConvLotto{Day="0",TDay="O"}

};

Vorrei selezionare TDay dato il Day

Di conseguenza

lotto = from TD in convLotto
where TD.Day == "1"
select TD.TDay;

ma mi restiruisce l'intera riga
grazie
La query è corretta.

Come fai a dire che ti restituisce l'intera riga? Come utilizzi poi lotto che dovrebbe essere un IEnumerable<string>?
176 messaggi dal 13 febbraio 2004
Cradle ha scritto:
La query è corretta.

Come fai a dire che ti restituisce l'intera riga? Come utilizzi poi lotto che dovrebbe essere un IEnumerable<string>?



io vorrei che mi restituisse il valore di TD, in questo caso "C"

grazie
Ok,

allora scrivi
var lotto = (from TD in convLotto
             where TD.Day == "1"
             select TD.TDay).Single();


Ciao,
m.

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.