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?
ddanbe
2,724
Professional Procrastinator
Featured Poster
Recommended Answers
Jump to Postint value type.. TextBox reference type you should new it...
All 3 Replies
Ramy Mahrous
401
Postaholic
Featured Poster
ddanbe
commented:
Arrrghhg! Thanks Ramy I should indeed KNEW it!
+4
ddanbe
2,724
Professional Procrastinator
Featured Poster
Ramy Mahrous
401
Postaholic
Featured Poster
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.