This is driving me crazy. texto.Count() without the lambda "works", it returns the same value as texto.Length and then porcentaje == 100 in all cases. But as soon as i put the lambda in there: texto.Count(x => x == c) it returns 0, so porcentaje == 0 every time. It just make no sense, if you read the code its obvious that texto contains c. texto is NOT empty and iam using DECIMAL for porcentaje. This happens with any string i pass as the parameter. Any idea of what is going on???
public static List<string[]> Estadistica (string texto)
{
//Devuelve la estadistica de aparicion de cada caracter del texto
string caracteresUnicos = new String(texto.Distinct().ToArray());
List<string[]> porcentajeCaracter = new List<string[]>();
foreach (char c in caracteresUnicos)
{
decimal porcentaje = texto.Count(x => x == c) / texto.Length * 100;
porcentajeCaracter.Add(new string[] { c.ToString(), porcentaje.ToString() });
}
porcentajeCaracter = porcentajeCaracter.OrderByDescending(arr => arr[1]).ToList();
return porcentajeCaracter;
}