快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

和记娱乐缅甸平台_机器人论坛



串行化可使工具被转换为某种外部的形式,比如以文件存储的形式供法度榜样应用,或经由过程法度榜样间的通讯发送到另一个处置惩罚历程。转换为外部形式的历程称为"串行化",而逆历程称为"反串行化"。

简介

请看例1中的示例,其将多个工具类型的值写入到一个新的磁盘文件中,关闭文件,接着再把这些值从新读取到内存中。

例1:

using namespace System;和记娱乐缅甸平台

using namespace System::IO;

using namespace System::Runtime::Serialization::Formatters::Binary;

int main()

{

array^ intArray = {10, 20, 30};

array^ floatArray = {

{1.2F, 2.4F},

{3.5F, 6.8F},

{8.4F, 9.7F}

};

DateTime dt = DateTime::Now;

Console::WriteLine("dt >{0}Serialize(file, "Hello");

/*3b*/ formatter->Serialize(file, intArray);

/*3c*/ formatter->Serialize(file, floatArray);

/*3d*/ formatter->Serialize(file, true);

/*3e*/ formatter->Serialize(file, dt);

/*3f*/ formatter->Serialize(file, 1000);

/*3g*/ formatter->Serialize(file, L'X');

/*3h*/ formatter->Serialize(file, 1.23456F);

/和记娱乐缅甸平台*4*/ file->Close();

//从文件中反串行化数据--即读取数据

/*5*/ file = File::Open("Sr01.ser", FileMode::Open);

/*6a*/ String^ s = static_cast(formatte和记娱乐缅甸平台r->Deserialize(file));

Console::WriteLine("String >{0}^ newIntArray =

static_cast^>(formatter->Deserialize(file));

Console::WriteLine("newIntArray:");

for (int i = 0; i Length; ++i)

{

Console::Write(" {0}", newIntArray[i]);

}

Consol和记娱乐缅甸平台e::WriteLine();

/*6c*/ array^ newFloatArray =

static_cast^>(formatter->Deserialize(file));

Console::WriteLine("newFloatArray:");

for (int i = 0; i (formatter->Deserialize(file));

Console::WriteLine("bool >{0}(form和记娱乐缅甸平台atter->Deserialize(file));

Console::WriteLine("newDT >{0}(formatter->Deserialize(file));

Console::WriteLine("int >{0}(formatter->Deserialize(file));

Console::WriteLine("wchar_t >{0}(formatter->Deserialize(file));

Console::WriteLine("float >{0}Close();

}

您可能还会对下面的文章感兴趣: