Index was out of range. Must be non-negative and less than the size of the collection.
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Rajkiran SwainRank #165 · 14.4K reputationPosted Dec 20, 2017, 9:06 PM EST
✓ Accepted answer+1
The error says "The index is out of range". That means you were trying to index an object with a value that was not valid. If you have two books, and I ask you to give me your third book, you will look at me funny. This is the computer looking at you funny. You said - "create a collection". So it did. But initially the collection is empty: not only is there nothing in it - it has no space to hold anything. "It has no hands".
+1
Dharmraj ThakurRank #577 · 4.2K reputationPosted Dec 20, 2017, 8:37 PM EST
0
You are accessing array element which is not present or which is out of array limit.
Example:
int[] a = new int[2];
int[0] = 1; //ok int[1] = 2; //ok int[2] = 3; //throw array index out of bound
Adeel Ahmed67 reputationPosted Dec 20, 2017, 9:32 PM EST
0
still getting error and my code is not working ..i am beggineer level and this is my assignment ..help me out brother..i want to transfer one gridview values to other gridview in same window frorm
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Lease_Managment_System12
{
public partial class Sale_info : Form
{
SqlConnection con = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=lease managment;Integrated Security=True;Pooling=False");
Rajkiran SwainRank #165 · 14.4K reputationPosted Dec 20, 2017, 9:06 PM EST
Dharmraj ThakurRank #577 · 4.2K reputationPosted Dec 20, 2017, 8:37 PM EST
Example:
int[] a = new int[2];
int[0] = 1; //ok
int[1] = 2; //ok
int[2] = 3; //throw array index out of bound
Adeel Ahmed67 reputationPosted Dec 20, 2017, 9:32 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts