[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

store list passed by reference

Bonghi

7/21/2008 12:13:00 PM

Hello All,

In a c# project I'm managing a List of objects of a custom class.

private List<MeshXNA> _Meshes = new List<MeshXNA>();

I then have a couple of different custom controls that display
information about the objects in that list (not only 3d).
I would like to achieve that the different controls could save the
reference to the list in order to be aware (at given intervals) of
further instances added.

at the moment I'm passing the data to the controls in this way:

bControl.SetModelList(ref _Meshes);

and the function is as follows:

public void SetModelList(ref
List<WinFormsGraphicsDevice.Device3D.MeshXNA> Meshes)
{
_meshes = Meshes;
// some initialization code
}

This seems to work, but I'm wondering if there's a better way of
sharing information structures across controls and form. Any
suggestion is welcome.

Best,
Claudio
1 Answer

Peter Duniho

7/21/2008 4:09:00 PM

0

On Mon, 21 Jul 2008 05:13:22 -0700, Bonghi <claudio.benghi@gmail.com>
wrote:

> [...]
> This seems to work, but I'm wondering if there's a better way of
> sharing information structures across controls and form. Any
> suggestion is welcome.

Other than the apparently pointless use of the "ref" keyword, I don't see
anything specifically wrong about the code you posted. However, if you're
interested in _doing_ something when the list instance is modified, you
might prefer to use the BindingList class rather than List. That class
provides events to notify you of changes to the list.

It's not clear how in the code you posted you would be detecting changes
to the list, but whatever you're doing, I think BindingList would probably
work better, since it's designed for that purpose.

Pete