0

When I want an array of integers with 4 rows and 2 columns I do
int[,] array = new int[4, 2];
and then use array[0, 0]=123; to set the first element.
So for the matrix input usercontrol I'm working on I thought I need something like :
TextBox[,] elements = new TextBox[5,5];(This compiles)
but when I try to access an element of this array ( e.g. elements[0,0].Name="foo";) I get a Null ref exeption.
When I do
elements[r, c] = new TextBox();
elements[r, c].Name = "foo";
All is well.
I'm confused here! Why two times new TextBox?

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Ramy Mahrous
1

int value type.. TextBox reference type you should new it...

Votes + Comments
Arrrghhg! Thanks Ramy I should indeed KNEW it!
0

Phew!
More than 10000 views in one day. Seems to me a lot of people have the same problem I had.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.