c#中string数组怎么转换到int 数组

来源:百度知道 编辑:UC知道 时间:2024/06/14 08:11:38
c#中string数组怎么转换到int 数组,请问大家怎么处理,在线等

不知道这样满足了你的要求没有?
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

string[] str = new string[10];

int[] s = new int[10];

Console.WriteLine("请输入十个字符串");

for (int i = 0; i < str.Length; i++)
str [i]= Console.ReadLine();

for (int i = 0; i < str.Length; i++)
s[i] = Convert.ToInt32(str[i]);

int a=0;
for (int i = 0; i < str.Length; i++)
a += s[i];
Console.WriteLine("a={0}" , a);

}
}
}

将字符串数组元素一个一个取出放入另一个int数组
namespace stringTOint
{
class Program
{
static void Main(string[] args)
{
string[] str =