将对象转换为字符串,获取要转换的特定数组对象 [英] cast an object as string, getting specific array object to cast
问题描述
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
string[] S = (string[])e.Argument;
DataGridViewCell C = (DataGridViewCell)e.Argument;
}
e.Argument恰好获得了以下3个对象:
The e.Argument gets exactly these 3 objects:
string hostname, string port , DataGridViewCell cell
object[] A = { hostname, port, cell };
backgroundWorker1.RunWorkerAsync(A);
如果没有DataGridViewCell,它就可以正常工作.
我不知道如何告诉它获取第一个和第二个对象并将它们转换为字符串.
然后获取第三个并将其转换为DataGridViewCell.
我觉得这是一个愚蠢的问题,我被卡住了!
提前谢谢.
Stelios K.
Without the DataGridViewCell it is working fine ofc.
I dunno how to tell it to get the first and the second object and cast them as string.
And then get the third and cast it as DataGridViewCell.
I feel like it''s a silly question, bt i''m stuck!
Thanks in advance.
Stelios K.
推荐答案
你可以试试这个
Hi,
Can you try with this
Object[] argumentArray = (Object[])e.Argument;
string hostName = (string)argumentArray[0];
string portNo = (string)argumentArray[1];
DataGridViewCell gridViewCell = (DataGridViewCell)argumentArray[2];
谢谢
Radhakrishnan G.
Thanks
Radhakrishnan G.
非常感谢Radhakrishnan ..
其实是在一分钟前找到的
Thanks a lot Radhakrishnan..
Actually found it a minute ago
object[] S = (object[])e.Argument;
DataGridViewCell C = (DataGridViewCell)S[2];
int temp = int.Parse(S[1].ToString());
Pinger ping = new Pinger();
bool job = false;
job = ping.StartPing(S[0].ToString(), temp);
首先要把em作为数组中的对象:
Object[] argumentArray = (Object[])e.Argument;
然后像你一样开始投射:
The whole point was first to get em as object in an array:
Object[] argumentArray = (Object[])e.Argument;
and then start casting like u did:
<pre lang="cs">string hostName = (string)argumentArray[0];<br />
string portNo = (string)argumentArray[1]</pre><br />
;
无论如何,感谢您的快速响应. :))
Anyway thanks for the quick response..! :))
这篇关于将对象转换为字符串,获取要转换的特定数组对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!