Your problem is that: listDonnees[cpt] is a List, you just take the inner list of you List>. If you want to know if the inner List contains the #FFFFFF you need to use .Contains()
listDonnees[cpt].Contains("#FFFFFF")
Or you use a second (nested) for - loop to check every string.
By the way: You can check easier by using this:
colore = listDonnees[cpt].Any(s =>new List() {"#FFFFFF", "#FFD700", "#FF6347"}.Contains(s));
So for you problem in particular:
int nbItems = listDonnees.Count ;
var hashCodes = new List() {"#FFFFFF", "#FFD700", "#FF6347"};
for(int cpt = 0; cpt < nbItems; cpt++)
{
string colorcode = string.Empty;
if(cpt + 1 < nbItems)
{
colorcode = listDonnees[cpt].FirstOrDefault(s => hashCodes.Contains(s));
}
if(colorcode != string.Empty)
{
colorcode |
//cpt++; See below!
}
else
{
var str = String.Join(",", listDonnees[cpt]);
str |
}
// I Think your cpt++; needs to be here:
cpt++;
}
I don't know you Model, so you might habe to change your @ViewBag accessing a bit.