高分悬赏 c#

来源:百度知道 编辑:UC知道 时间:2024/06/27 19:45:34
static void Test(out string c)
{
string mystring = "a1b1c1d";
int count = mystring.Split().Length - 1;
string[] a = mystring.Split('1');
c = "";
foreach (string b in a)
{
c = b;
}

}

static void Main(string []args)
{
string a;
Test(out a);
Console.WriteLine(a);
Console.ReadLine();
}

结果是输出
d

很正常!
问题是我需要在主函数中作循环,输出a,b,c,d

怎么写???

高分悬赏,马上结帖!
不要在主函中中任何处理字符串!

using System;
using System.Collections.Generic;
using System.Text;

namespace test
{
class Class4
{
static string[] Test()
{
string mystring = "a1b1c1d";
int count = mystring.Split().Length - 1;
string[] a = mystring.Split('1');
return a;
}

static void Main(string[] args)
{
string[] a = Test();
foreach (string i in a)
{
Console.WriteLine(i);

}

Console.ReadLine();
}
}
}

Test函数有问题吧,里面那个FOREACH循环造成循环到最后C的值永远是字符串mystring中的最后一个字符,所以输出总是d

static void Test(out string c)
{
string mystring = "a1b1c1d";
int count = mystring.Split().Length - 1;
string[] a = mystring.Split('1');
c = "&