[Solved] c# – Index out of range [closed]


You are asking for 200 tweets and you have only sized your string array to 50, so it blows up on the 51st tweet processed.

This code is the problem:

var tweets = service.ListTweetsOnHomeTimeline(
    new ListTweetsOnHomeTimelineOptions { Count = 200 });
string[] twt_id = new string[50];

Either change the number of tweets you are requesting or change the size of the string array to match the number of tweets requested.

UPDATE:

This logic is counter-productive, to say the least:

if (i == 0)
{
    twt_id[i] = tweet.Id.ToString();
}
id = Convert.ToInt64(replyid);
twtid = tweet.Id.ToString();

i = i + 1;
twt_id[i] = twtid;

You are adding the same tweet to two different indexes in your string array, change your code to this:

twt_id[i] = tweet.Id.ToString();
i = i + 1;

What is the purpose of replyid = tweet.InReplyToStatusId.ToString();, you are setting a value every loop iteration only to not use it anywhere, same with id = Convert.ToInt64(replyid); and increment = increment + 1;. You definitely need to clean up unused logic in your code.

2

solved c# – Index out of range [closed]