![]() |
|
|
|||
|
store list passed by reference
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 |
|
|||
|
Re: store list passed by reference
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 |
![]() |
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|