var objTypeIndex = from u in context.sistema_DocType_Index where u.docTypeId == id select u.indexId;
indexIds = objTypeIndex.ToList();
int count = indexIds.Count();
string[] names = new string[] {};
int i = 0;
foreach (int indexId in indexIds)
{
//resgata nome do indice e armazena em um array
string strIndiceID = indexId.ToString();
int indiceID = Convert.ToInt32(strIndiceID);
var objIndexName = from u in context.sistema_Indexes where u.id == indiceID select u.idName;
name =
names[i] = objIndexName.First();
i++;
}
This line above the last: names[i] = objIndexName.First();
gives the following error:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
I know what that means.. I just can´t figure out why.
string[] namesas an empty array, settingint i = 0, then accessingnames[i]- which isnames[0]- which doesn't exist, since your length is 0, not 1.foreachloop? Just useindexIdinstead.