C# pointers??

I

ibiza

Hi All,

I am creating a C# Windows Forms application,
here is my problem :

in my main form, I have this variable : List<List<cBar>> bars;

I will save you the initialization and loading phases of this, but at
the end, this variable contains well, a list of list of bars. For the
sake of the example, let's say a bar is simply an int, so that
variable would roughly be equivalent to a jagged 2-d array of
integers.

bars[0] = { 1, 4, 7, 8, 9 }
bars[1] = {6, 3, 5 }
bars[2] = { 2, 6, 8, 9, 8, 7}
....

I also have a usercontroler on the form. Again for simplicity's sake,
let's say it simply prints all the bars (ints)
For now, as I am still testing, I hardcoded one such list of bars in
the user control and it works great.

So the next step is to integrate the user control in the form so that
when I select a List of bars from the main form ( let's say bars[0] ),
the user control uses it and prints it.

My main concern now : I do not want to pass a List<cBar> by value
parameter to the user control. I want of course to pass a reference of
the list instead, to avoid the tedious process of copying all the data
in the list.

So, for now, when I select a list, I use the following :

userControl.LoadData( bars[selectedList] );

I need to pass a reference to the user control instead of copying the
whole list, how do I do?

Hope this is clear enough,
thanks to all who help!
 
I

Ignacio Machin ( .NET/ C# MVP )

Hi All,

I am creating a C# Windows Forms application,
here is my problem :

in my main form, I have this variable : List<List<cBar>> bars;

I will save you the initialization and loading phases of this, but at
the end, this variable contains well, a list of list of bars. For the
sake of the example, let's say a bar is simply an int, so that
variable would roughly be equivalent to a jagged 2-d array of
integers.

bars[0] = { 1, 4, 7, 8, 9 }
bars[1] = {6, 3, 5 }
bars[2] = { 2, 6, 8, 9, 8, 7}
...

I also have a usercontroler on the form. Again for simplicity's sake,
let's say it simply prints all the bars (ints)
For now, as I am still testing, I hardcoded one such list of bars in
the user control and it works great.

So the next step is to integrate the user control in the form so that
when I select a List of bars from the main form ( let's say bars[0] ),
the user control uses it and prints it.

My main concern now : I do not want to pass a List<cBar> by value
parameter to the user control. I want of course to pass a reference of
the list instead, to avoid the tedious process of copying all the data
in the list.

So, for now, when I select a list, I use the following :

userControl.LoadData( bars[selectedList] );

I need to pass a reference to the user control instead of copying the
whole list, how do I do?

Hope this is clear enough,
thanks to all who help!

You do pass it by reference. as List<> is a reference type.
 
M

Marc Gravell

lists are reference-types; that means that you *are* passing just a
reference (comparable to a pointer), and the data is never copied.

Are you having an issue in this area? If so, could you describe the
symptom and/or provide any error messages you are seeing?

Marc
http://marcgravell.blogspot.com/
 
I

ibiza

ok great :)

I do not have an issue beside that I assumed that was passed by
value...

thanks!
 

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

Top