在c#中使用foreach [英] using foreach in c#
本文介绍了在c#中使用foreach的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨frens,
我有一串数组
ex:string [] abc = new string [] {3,2,1};
如何使用foreach获得值3
如果我使用
foreach(int x in abc)
{
}
x返回51,相当于ascii 3但我需要3 ..
请帮帮我...
提前感谢
darshan
Hi frens,
I have a string of arrays
ex :string[] abc= new string[] { "3", "2", "1" };
how can i get the value 3 using foreach
if i use
foreach(int x in abc )
{
}
x is returning 51 which is ascii equivalent of 3 but i need 3 ..
please help me...
thanks in advance
darshan
推荐答案
string[] abc = new string[] { "3", "2", "1" };
foreach (string s in abc)
{
//Your code here
}
而不是 int
在foreach中使用 string
。我已经尝试了上面的代码,它的工作正常。
Instead of int
in foreach use string
. I have tried above code, its working fine.
我有一串数组
I have a string of arrays
string[] abc= new string[] { "3", "2", "1" };
foreach(string x in abc )
{
Console.WriteLins(x);
}
hi,
使用此: -
Use this :-
string[] abc = new string[] { "3", "2", "1" };
foreach (string x in abc)
{
Console.Write(Convert.ToInt32(x));
}
这篇关于在c#中使用foreach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文