Object reference not set to an instance of an object.

N

nalbayo

See code...please


ListItem[] MakeNumber()
{
ListItem[] items = new ListItem[50];
for (int i = 0; i < 50; i++)
{
items.Text = i.ToString();
}
return items;
}



Error message is here

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.


What's the problem??
 
T

Tim Cartwright

You did not create items, you created an array of 50 of them that are
null. You need to create them.

for (int i = 0; i < 50; i++)
{
items = new ListItem();
items.Text = i.ToString();
}

should work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top