Uso il framework di entità, un'entità chiamata "tasso di interesse", il nome del set di entità è "InterestRateSet".
Ci sono due proprietà, Tempo e Tasso, entrambe sono doppie. I dati ad esempio, firstcolumn 0, 0.5, 1, secondcolumn 0, 0.01, 0.015
Come posso ottenere un array 3row2column usando LINQ da InterestRateSet? Qualcuno potrebbe mostrarmi l'esempio di codice per favore? Grazie in anticipo!
risposte:
1 per risposta № 1public string[,] GetInterestRates()
{
var array =(from ir in ctx.InterestRateSet
select new List<string>{ ir.Time.ToString() , ir.Rate.ToString()}).ToArray();
return CreateRectangularArray(array);
}
static T[,] CreateRectangularArray<T>(IList<T>[] arrays)
{
// TODO: Validation and special-casing for arrays.Count == 0
int minorLength = arrays[0].Count();
T[,] ret = new T[arrays.Length, minorLength];
for (int i = 0; i < arrays.Length; i++)
{
var array = arrays[i];
if (array.Count != minorLength)
{
throw new ArgumentException
("All arrays must be the same length");
}
for (int j = 0; j < minorLength; j++)
{
ret[i, j] = array[j];
}
}
return ret;
}