字符串数组到Int数组 [英] String Array to Int Array

查看:60
本文介绍了字符串数组到Int数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我在以下代码中得到2个错误,我无法调试,没有一些

帮助。

他们都在TryParse中功能。看似简单。错误

低于。

private void ConvertLabelStringToArray(string p)

{

string [] CardsToBeSortedArray = p.Split('''');

uint [] IntCard = new uint [CardsToBeSortedArray.Length];

foreach(CardsToBeSortedArray中的字符串卡)

{

UInt32.TryParse(Card,out IntCard);


}


}


错误1''uint.TryParse(string,out

uint)''的最佳重载方法匹配有一些无效的参数

错误2参数''2'':无法从''out uint []''转换为'out out uint''


我会很感激一些启发

谢谢

Mike

解决方案

Hello


我在以下代码中得到2个错误,我无法调试,没有一些

帮助。

他们都在试用解析功能。看似简单。错误

低于。

private void ConvertLabelStringToArray(string p)

{

string [] CardsToBeSortedArray = p.Split('''');

uint [] IntCard = new uint [CardsToBeSortedArray.Length];

foreach(CardsToBeSortedArray中的字符串卡)

{

UInt32.TryParse(Card,out IntCard);

}


}


错误1''uint.TryParse(字符串,

out

uint)的最佳重载方法匹配''有一些无效的参数

错误2参数''2'':无法从'out out uint []''转换为'out out uint''

我会感激一些启发



你不能通过uint [],只需要一个uint。你必须这样做:


private void ConvertLabelStringToArray(string p)

{

string [] CardsToBeSortedArray = p.Split ('''');

uint [] IntCard = new uint [CardsToBeSortedArray.Length];

for(int i = 0; i< CardsToBeSortedArray.Length; i ++)

UInt32.TryParse(CardsToBeSortedArray [i],out IntCard [i]);

}


但是,从那以后您正在使用.NET Framework 2.0,您可能会尝试使用Array.ConvertAll< TInput,

TOutput方法:


private static void ConvertLabelStringToArray(string p)

{

string [] CardsToBeSortedArray = p.Split('''');

uint [] IntCard = Array.ConvertAll< ; string,uint>(CardsToBeSortedArray,delegate(string

card)

{

uint result;

UInt32 .TryParse(卡,结果);

返回结果;

});

}

最好的问候,

达斯汀坎贝尔

Developer Express Inc.


AMP写道:


Hello

我在以下代码中得到2个错误,我无法调试而没有一些

帮助。

它们都在TryParse函数中。看似简单。错误

低于。

private void ConvertLabelStringToArray(string p)

{

string [] CardsToBeSortedArray = p.Split('''');

uint [] IntCard = new uint [CardsToBeSortedArray.Length];

foreach(CardsToBeSortedArray中的字符串卡)

{

UInt32.TryParse(Card,out IntCard);


}


}


错误1''uint.TryParse(string,out

uint)''的最佳重载方法匹配有一些无效的参数

错误2参数''2'':无法从''out uint []''转换为'out out uint''



As第二个错误状态,TryParse需要一个''out uint''作为它的第二个

参数,你传递''uint []''。你需要传递一个特定的索引

的数组。我会按如下方式重做循环:


private void ConvertLabelStringToArray(string p)

{

string [] CardsToBeSortedArray = p .Split('''');

uint [] IntCard = new uint [CardsToBeSortedArray.Length];

for(int i = 0; i< CardsToBeSortedArray。长度; i ++)

{

uint.TryParse(CardsToBeSortedArray [i],out IntCard [i]);

}

}

-

Tom Porterfield


Dustin Campbell写道:


你不能通过uint [],只需要一个uint。你必须这样做

这个:

private void ConvertLabelStringToArray(string p)

{

string [] CardsToBeSortedArray = p.Split('''');

uint [] IntCard = new uint [CardsToBeSortedArray.Length];

for(int i = 0; i< CardsToBeSortedArray.Length; i ++)

UInt32.TryParse(CardsToBeSortedArray [i],out IntCard [i]);

}


但是,由于你使用的是.NET Framework 2.0,你可能会尝试使用

Array.ConvertAll< TInput,TOutput方法来代替:


private static void ConvertLabelStringToArray(string p)

{

string [] CardsToBeSortedArray = p.Split('''');

uint [] IntCard = Array.ConvertAll< string,uint>(CardsToBeSortedArray,

delegate(string card)

{

uint result;

UInt32.TryParse(卡,结果);

返回结果;

});

}



帮助我理解一些事情。第二个实现是更多代码,

需要泛型和委托,并且比第一个更难阅读。那么

这样做有什么好处?

-

Tom Porterfield


Hello
I get 2 errors in the following code that I cant Debug without some
help.
They are both in the TryParse function. Seems simple enough.The Errors
are Below.
private void ConvertLabelStringToArray(string p)
{
string[] CardsToBeSortedArray = p.Split('' '');
uint[] IntCard = new uint[CardsToBeSortedArray.Length];
foreach (string Card in CardsToBeSortedArray)
{
UInt32.TryParse(Card, out IntCard);

}

}

Error 1 The best overloaded method match for ''uint.TryParse(string, out
uint)'' has some invalid arguments
Error 2 Argument ''2'': cannot convert from ''out uint[]'' to ''out uint''

I would appreciate some enlightening
Thanks
Mike

解决方案

Hello

I get 2 errors in the following code that I cant Debug without some
help.
They are both in the TryParse function. Seems simple enough.The Errors
are Below.
private void ConvertLabelStringToArray(string p)
{
string[] CardsToBeSortedArray = p.Split('' '');
uint[] IntCard = new uint[CardsToBeSortedArray.Length];
foreach (string Card in CardsToBeSortedArray)
{
UInt32.TryParse(Card, out IntCard);
}

}

Error 1 The best overloaded method match for ''uint.TryParse(string,
out
uint)'' has some invalid arguments
Error 2 Argument ''2'': cannot convert from ''out uint[]'' to ''out uint''
I would appreciate some enlightening

You can''t pass a uint[] where only a uint is expected. You have to do this:

private void ConvertLabelStringToArray(string p)
{
string[] CardsToBeSortedArray = p.Split('' '');
uint[] IntCard = new uint[CardsToBeSortedArray.Length];
for (int i = 0; i < CardsToBeSortedArray.Length; i++)
UInt32.TryParse(CardsToBeSortedArray[i], out IntCard[i]);
}

But, since you''re using .NET Framework 2.0, you might try using the Array.ConvertAll<TInput,
TOutputmethod instead:

private static void ConvertLabelStringToArray(string p)
{
string[] CardsToBeSortedArray = p.Split('' '');
uint[] IntCard = Array.ConvertAll<string, uint>(CardsToBeSortedArray, delegate(string
card)
{
uint result;
UInt32.TryParse(card, out result);
return result;
});
}
Best Regards,
Dustin Campbell
Developer Express Inc.


AMP wrote:

Hello
I get 2 errors in the following code that I cant Debug without some
help.
They are both in the TryParse function. Seems simple enough.The Errors
are Below.
private void ConvertLabelStringToArray(string p)
{
string[] CardsToBeSortedArray = p.Split('' '');
uint[] IntCard = new uint[CardsToBeSortedArray.Length];
foreach (string Card in CardsToBeSortedArray)
{
UInt32.TryParse(Card, out IntCard);

}

}

Error 1 The best overloaded method match for ''uint.TryParse(string, out
uint)'' has some invalid arguments
Error 2 Argument ''2'': cannot convert from ''out uint[]'' to ''out uint''

As the second error states, TryParse needs a ''out uint'' as its second
parameter, you are passing ''out uint[]''. You need to pass a specific index
of the array. I would rework the loop as follows:

private void ConvertLabelStringToArray(string p)
{
string[] CardsToBeSortedArray = p.Split('' '');
uint[] IntCard = new uint[CardsToBeSortedArray.Length];
for (int i = 0; i < CardsToBeSortedArray.Length; i++)
{
uint.TryParse(CardsToBeSortedArray[i], out IntCard[i]);
}
}
--
Tom Porterfield


Dustin Campbell wrote:

You can''t pass a uint[] where only a uint is expected. You have to do
this:
private void ConvertLabelStringToArray(string p)
{
string[] CardsToBeSortedArray = p.Split('' '');
uint[] IntCard = new uint[CardsToBeSortedArray.Length];
for (int i = 0; i < CardsToBeSortedArray.Length; i++)
UInt32.TryParse(CardsToBeSortedArray[i], out IntCard[i]);
}

But, since you''re using .NET Framework 2.0, you might try using the
Array.ConvertAll<TInput, TOutputmethod instead:

private static void ConvertLabelStringToArray(string p)
{
string[] CardsToBeSortedArray = p.Split('' '');
uint[] IntCard = Array.ConvertAll<string, uint>(CardsToBeSortedArray,
delegate(string card)
{
uint result;
UInt32.TryParse(card, out result);
return result;
});
}

Help me understand something. The second implementation is more code,
requires generics and delegates, and is harder to read, than the first. So
what are the advantages of doing it that way?
--
Tom Porterfield


这篇关于字符串数组到Int数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆