Manipulación de propiedad escrita como Lista
Frecuentes
Visto 52 veces
-1
I have a Property which is of List Type as below.
private List<ListCOP_PAYLOAD> m_COP_DATA = new List<ListCOP_PAYLOAD>();
public List<ListCOP_PAYLOAD> COP_DATA
{
get
{
return m_COP_DATA;
}
set
{
m_COP_DATA = value;
FireNewSMode_Data();
}
}
Each time I add data I use the following:
m_exchangedata.COP_DATA = Mstruct.lMCOPStruct;
But it just increases the list size with the new data variables.
I want to clear the previous data so I used
m_exchangedata.COP_DATA.Clear();
Editado: I use it in this order
m_exchangedata.COP_DATA.Clear();
m_exchangedata.COP_DATA = Mstruct.lMCOPStruct;
pero eso no parece funcionar.
I get InvalidOperationException : Sequence contains no elements.
The FireNewSMode_Data just fires off an event with the data if the event handler is not null.
Cualquier ayuda sería apreciada.
Gracias de antemano.
1 Respuestas
1
Put a condition of count before clearing the COP_DATA
lista:
if(m_exchangedata.COP_DATA.Count > 0)
{
m_exchangedata.COP_DATA.Clear();
}
m_exchangedata.COP_DATA = Mstruct.lMCOPStruct;
respondido 27 nov., 13:07
Great comment and I used it earlier in the code. My problem was that both m_exchangedata and Mstruct are reference types so when I was clearing COP_DATA I was also clearing lMCOPStruct. I should have noticed that sooner. - C
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# list properties or haz tu propia pregunta.
Puedes facilitar
FireNewSMode_Data
¿método? - Grundydoes not seem to work
-> this does not make much sense. - King King