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?

Recommended Answers

All 3 Replies

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

commented: Arrrghhg! Thanks Ramy I should indeed KNEW it! +4

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

I am proud I could solve it to my expert :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.