| | |
Null reference in array
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
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?
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?
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
int value type.. TextBox reference type you should new it...
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
I am proud I could solve it to my expert
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
![]() |
Similar Threads
- need Help in store Datagrid item in an array (VB.NET)
- Help with class project (Java)
- Sorting 2D Dynamic array of integers , Snake Style (C)
- memory allocation ptr to array? how? (C)
- Urgent Help Needed!!!! Plzzz (Java)
- Java practice questions (Java)
- Array Values not found in Methods (Java)
- pointer/reference ? issues ... need help with simple code (C++)
- How do I create a program using an Array ? (C++)
Other Threads in the C# Forum
- Previous Thread: Server Files in Combobox ??
- Next Thread: Complete task THEN continue
| Thread Tools | Search this Thread |
.net access algorithm api array asp.net barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime dbconnection degrees design development draganddrop drawing encryption enum event eventhandlers excel file firefox form format forms function gdi+ httpwebrequest image index input install java label libraries list listbox loop mandelbrot marshalbyrefobject math mouseclick movingimage mysql mysql.data.client operator path photoshop php picturebox pixelinversion post programming radians regex remote remoting resourcefile richtextbox server sleep socket sql statistics stream string study system.servicemodel table tcpclientchannel text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf xml






