Tuesday, January 27, 2009

Storage: MAP in C++ and List in C# (1)

MAP in C++ and List in C#
=====================

(1) List in C#

For C#, if we want to store complicated data, we can use array list like following:
public class General
{
public BluetoothDevice[] DeviceList = new BluetoothDevice[(int)
MaxSearchNumber.MaxDeviceNumer];
...
}

while BluetoothDevice is a Class:

public class BluetoothDevice
{
private string m_Name;
private string m_Address;
private bool m_Paired;
private int m_index;

private string m_type;

public string Type
{
get { return m_type; }
set { m_type = value; }
}
///
/// Constructor
///

public BluetoothDevice()
{
m_Name = "";
m_Address = "";
m_Paired = false;
m_index = -1;
m_type = "";
}

public int Index
{
get { return m_index; }
set { m_index = value; }
}
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}

public string Address
{
get { return m_Address; }
set { m_Address = value; }
}
}

To use:
for (int i = 0; i < m_General.DeviceList.Length; i++)
m_General.DeviceList[i] = new BluetoothDevice();

m_General.DeviceList[m_General.DeviceCounter].Name = somevalue;

No comments: