我是一名有用的助手,能够进行文本翻译。
我有一个带有DataGridView的Windows窗体,并将特定列的值读入列表中。我需要在单个内存映射文件中共享列表的所有值,但以下是我的担忧: 1. 找到以字节为单位的列表大小。 2. 需要共享列表的所有项。
这是我的示例代码,我正在共享单个变量值:
假设我的列表有以下项目:1.苹果2.芒果3.菠萝。请指导我如何处理上述代码。
我有一个带有DataGridView的Windows窗体,并将特定列的值读入列表中。我需要在单个内存映射文件中共享列表的所有值,但以下是我的担忧: 1. 找到以字节为单位的列表大小。 2. 需要共享列表的所有项。
这是我的示例代码,我正在共享单个变量值:
string MyName = "Seema";
int totalBytes = MyName.Length * sizeof(Char) + 4;
public List<string> myList = new List<string>();
MemoryMappedFile MyText = MemoryMappedFile.CreateOrOpen("MyGlobalData", howManyBytes);
byte[] array1 = new byte[howManyBytes];
array1 = GetBytes(Name);
using (var accessor = MyText.CreateViewAccessor(0, array1.Length))
{
accessor.WriteArray(0, array1, 0, array1.Length);
}
static byte[] GetBytes(string str)
{
byte[] bytes = new byte[str.Length * sizeof(char)];
System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
return bytes;
}
假设我的列表有以下项目:1.苹果2.芒果3.菠萝。请指导我如何处理上述代码。