本文介绍了将System :: object转换为字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在后台工作程序通过串行端口接收数据的过程中,我需要返回字符串的三维数组。
I need to return four dimensional array of strings during the work of background worker which is receiving data via serial port.
在后台工作程序中:
array<String^>^ Received = gcnew array<String^>(4);
backgroundWorker1->ReportProgress(10,Received);
报告进度:
private: System::Void backgroundWorker1_ProgressChanged(System::Object^ sender, System::ComponentModel::ProgressChangedEventArgs^ e)
{
array<String^>^ Received2 = gcnew array<String^>(4);
Received2 =(e->UserState);
}
我正在:
这并不奇怪,但是如何将 UserState
转换并分配给字符串数组
?
which is not a surprise, but how to convert and assign UserState
to string array
?
推荐答案
您需要将对象句柄转换为数组句柄,然后检查nullptr以查看转换是否成功,例如:
You need to cast the object handle to an array handle then check for a nullptr to see if the cast was successful e.g:
array<String^>^ Received2 = dynamic_cast<array<String^>^>(e->UserState);
if (Received2 != nullptr)
{
// Cast was successful, safe to use Received2.
}
else
{
// Cast failed, do not use Received2.
}
这篇关于将System :: object转换为字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!