简体   繁体   中英

How to fix 'Index was outside the bounds of the array.' while adding to list

I am trying to add items to a list but I am facing the following

Index was outside the bounds of the array.

error while adding an item. I'm using BOT Framework.

I have tried changing List to ConcurrentBag also but it doesn't solve the issue.

public static async Task refreshCategoryLuis(ITurnContext turnContext)
{
    var luisCategoryIntents = await getCatagoryLuisIntentsList("*****-********-******-****");
    ConcurrentBag<string> categoryList = new ConcurrentBag<string>();

    for (int i = 0; i <= luisCategoryIntents.Length; i++)
    {
        categoryList.Add(luisCategoryIntents[i].Name);
    }
}

i can not equal Length because when it is, it crosses the bound so <= needs to be < .

for (int i = 0; i <= luisCategoryIntents.Length; i++)

This line needs to be:

for (int i = 0; i < luisCategoryIntents.Length; i++)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM