数据如下
一、1 2 3 44
二、a b c d
三、e f现在要写一个循环
1ae,1af,1be,1bf...............问题是,行数是未知的,可能是三行也可以是十行。
一、1 2 3 44
二、a b c d
三、e f现在要写一个循环
1ae,1af,1be,1bf...............问题是,行数是未知的,可能是三行也可以是十行。
解决方案 »
- 用vs2010调试程序生成的.vshost.exe进程终止不了
- 跪求C# 第三方控件 DotNetBar 的中文教程
- 请教:C# 取值与设值 get set ?
- c#SOCKET接收数据问题
- dataGridView有没有办法设置某个字段为0时改变该行背景色
- Session["dxef"]="aa"后,可以string strTmp=Session["dxef"]+""而不可以string strTmp=Session["dxef"]?
- c# 多层结构编程
- .net中如何访问一个dll.是通过反射么?
- 如何从文本框中输入的字串创建实例?
- 痛苦哇!装了两个月都没装上vs.net,帮帮我.
- 从TXT读取并存入到DataTable
- 用 c# 还是 delphi 开发桌面应用程序?(保证结帖给分)
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<List<string>> list = new List<List<string>>()
{
new List<string>() { "1", "2", "3", "44" },
new List<string>() { "a", "b", "c", "d" },
new List<string>() { "e", "f" }
};
var result = list.Aggregate((current, total) => total.Join(current, (string x) => 1, (string y) => 1, (string a, string b) => b + a).ToList());
result.ForEach(x => { x.ToList().ForEach(y => Console.Write(y + " ")); Console.WriteLine(); });
}
}
}
{
List<string[]> list = new List<string[]>()
{
new string[]{"1","2","3","44"},
new string[]{"a","b","c","d"},
new string[]{"e","f"} };
Fun(list, 0, "");
Console.ReadLine();
}
static void Fun(List<string[]> list, int Row, string str)
{
if (Row == list.Count)
Console.WriteLine(str);
if (Row < list.Count)
{
for (int i = 0; i < list[Row].Length; i++)
Fun(list, Row + 1, str + list[Row][i]);
}
}
{
new string[]{"1","2","3","44"},
new string[]{"a","b","c","d"},
new string[]{"e","f"} };
Fun(list, 0, "");
Console.ReadLine();
}
static void Fun(List<string[]> list, int Row, string str)
{
if (Row == list.Count)
Console.WriteLine(str);
if (Row < list.Count)
{
for (int i = 0; i < list[Row].Length; i++)
Fun(list, Row + 1, str + list[Row][i]);
}
好强悍呀!! 菜鸟一枚, 第一个想到的就是三层循环,嘿嘿: List<List<string>> list = new List<List<string>>()
{
new List<string>() { "1", "2", "3", "44" },
new List<string>() { "a", "b", "c", "d" },
new List<string>() { "e", "f" }
}; List<string> lstMsg = new List<string>();
foreach (string str1 in list.ElementAt(0))
{
foreach (string str2 in list.ElementAt(1))
{
foreach (string str3 in list.Last())
{
lstMsg.Add(String.Format("{0} - {1} - {2}", str1, str2, str3));
}
}
} lstMsg.ForEach( x => Console.WriteLine(x) );Linq !!!