请教各位高手:现在有几个词语:厂商、版本、平台、分辨率、创建时间、适配时间我想把这几个词语自由组合把这些自由组合的结果全部输出出来,
组合是任意的,可以2个词语,也可以1个词,更多也可以,只要不大于词语的总数就行
组合是任意的,可以2个词语,也可以1个词,更多也可以,只要不大于词语的总数就行
解决方案 »
- C#窗体控件TabControl的使用
- 有个数据库脚本文件1.sql,里面有很多条语句组成,如何在c#程序中来执行它
- MDI 子窗体上无控件 方向键被自动捕捉用于切换窗体
- 字母字符串公式如何计算?请高手指点啊!
- 一个学过JEE的学生应该去学习.NET的知识
- 用visual studio2003,創建c# web應用工程時為什麼總是出現下面的錯誤呢?
- 求一个积木放盒子的算法
- "Invalid parameter used" 使用 System.Drawing.Image.FromStream出现这样的错误
- 请教如何使用C#做一个文件浏览器?分不够可以再给!
- OleDb的Bug?
- Datetime 转换失败【非常邪门】
- 按钮被单击是怎么判断出的?
建议你是有 枚举enum
或者自定义结构体
l.add("厂商");
l.add("版本");
l.add("平台");
l.add("分辨率");
l.add("创建时间");
l.add("适配时间"); 然后通过随机数字 来去list中的字符串,需要注意的是 list是从0开始的
list(0)是“厂商”生成不重复随机数字的方法
public static string RandomNumber(int length)
{
string result = "";
Random random = new Random(unchecked((int)DateTime.Now.Ticks));
for (int i = 0; i < length; i++)
{
result += random.Next(10).ToString();
}
return result;
}
static void Main(string[] args)
{
Random ran = new Random();
for (int i = 0; i < 10; i++)
{
Console.WriteLine(GetRandomFromSource(ran));
}
} public static string GetRandomFromSource(Random ran)
{
string result = "";
string[] source = { "厂商", "版本", "平台", "分辨率", "创建时间", "适配时间" };
var tempRet = new List<string>();
int current = ran.Next(1 << source.Length);
for (int j = 0; j < source.Length; j++)
{
if (((1 << j) & current) != 0)
{
tempRet.Add(source[j]);
}
} foreach (var t in tempRet)
{
result += t;
}
return result;
}
class Program
{
List<string> result = new List<string>();
string[] source = { "厂商", "版本", "平台", "分辨率", "创建时间", "适配时间" };
int totalLoop;
int currentLoop;
static void Main(string[] args)
{
Program p = new Program();
List<string> result = p.GetRandomFromSource();
int number = 0;
for (int i = 0; i < result.Count; i++)
{
Console.WriteLine(result[i]);
number++;
}
Console.WriteLine("Total is " + number + " lines");
Console.ReadLine();
} private List<string> GetRandomFromSource()
{
totalLoop = source.Length;
currentLoop = 1;
Loop();
return result;
} private void Loop()
{
if (currentLoop == 1)
{
for (int k = 0; k < source.Length; k++)
{
result.Add(source[k]);
}
if (currentLoop == totalLoop)
return;
}
currentLoop++;
int count = result.Count;
for (int k1 = source.Length * (currentLoop - 2); k1 < count; k1++)
{
for (int k2 = 0; k2 < source.Length; k2++)
{
string temp = result[k1] + "," + source[k2];
result.Add(temp);
}
}
if (currentLoop == totalLoop)
return;
Loop();
}
}
方法有点笨,不过应该可行吧,试试~