Sorry for deleting the previous thread by mistake, it was acceptable answer. I would like to thank for that.
I have other issue related to this
I have class which contains the byte array to store discrete hex data.....
#region//==================================================DataFrameGenericClass
public class DataFrameGenericClass
{
private UInt16 m_Page;
private Byte[] m_LIN_Array_Message1; // 7 byte Data + ID + CRC = 9 Byte Total
private Byte[] m_LIN_Array_Message2; // 7 byte Data + ID + CRC = 9 Byte Total
public DataFrameGenericClass(UInt16 Page)
{
this.m_Page = Page;
this.m_LIN_Array_Message1 = new Byte[9];
this.m_LIN_Array_Message2 = new Byte[9];
}
public UInt16 Page { get { return m_Page; } set { m_Page = value; } }
public Byte[] LIN_Array_Message1 { get { return m_LIN_Array_Message1; } set { m_LIN_Array_Message1 = value; } }
public Byte[] LIN_Array_Message2 { get { return m_LIN_Array_Message2; } set { m_LIN_Array_Message2 = value; } }
}
#endregion
I have Generic type with constraints
#region//==================================================DataFrameCollection
public class DataFrameCollection<T> : IEnumerable<T> where T : DataFrameGenericClass // "where T : Employee" Constraining type to Employee class only, (not to string or int).
{
List<T> DataFrameList = new List<T>();
public void Add(T element) // Add element at the bottom of the index (new data entry)
{
DataFrameList.Add(element);
}
public T Get(int index) // Get element at specfied index
{
return DataFrameList[index];
}
public void Update(int index, UInt16 Page) ///<<<<<< Previous C#Corner thread
{
T record = Get(index);
record.Page = Page;
}
public void Modify_LINArrayMessage1(int index, Byte[] message) // Modify element array at specfied index <<<<<< Previous C#Corner thread
{
T record = Get(index);
record.LIN_Array_Message1 = message;
//DataFrameList[index].LIN_Array_Message1 = message;
}
public void Modify_LINArrayMessage2(int index, Byte[] message) // Modify element at specfied index
{
DataFrameList[index].LIN_Array_Message2 = message;
}
public void Modify_Page(int index, UInt16 page16) // Modify element at specfied index
{
DataFrameList[index].Page = page16;
}
public void TraceDumpData(int index)
{
Trace.WriteLine("RawMessage:" + DataFrameList[index].RawMessage.ToString());
Trace.WriteLine("Page:"+DataFrameList[index].Page.ToString("X4"));
//### TODO Display LIN Array Message
}
//foreach support
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return DataFrameList.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return DataFrameList.GetEnumerator();
}
}
#endregion
Then I have main code
DataFrameCollection<DataFrameGenericClass> DataFrameLIN = new DataFrameCollection<DataFrameGenericClass>();
.... I created the record
DataFrameLIN.Add(new DataFrameGenericClass(0));
DataFrameLIN.Add(new DataFrameGenericClass(1));
DataFrameLIN.Add(new DataFrameGenericClass(2));
.....
Byte[] LinAddress1 = new Byte[9];
Byte[] LinAddress2 = new Byte[9];
....
// Fill data with LinAddress1 and LinAddress2
LinAddress2[0] 0x01; LinAddress2[1] 0xFF; etc etc etc
I then update generic records, note that index = 0;
DataFrameLIN.Modify_LINArrayMessage1(0, LinAddress1);
DataFrameLIN.Modify_LINArrayMessage2(0, LinAddress2);
I then modify the LinAddress1 and 2
LinAddress2[0] 0x11; LinAddress2[1] 0x44; etc etc etc
I then update generic records, note that index = 1;
DataFrameLIN.Modify_LINArrayMessage1(1, LinAddress1);
DataFrameLIN.Modify_LINArrayMessage2(1, LinAddress2);
But during debug, I found that the array within index 0 has same value as index 1 array.
It seem it reference to LinAddress1 rather than value as this would explain same value. How to isolate reference between these two so it retains corrects value?
Thanks
PS:Again, very sorry for deleting the thread, it was a mistake as I click too quickly!