如何在C#中组合字符串? [英] How to make a combination of strings in C#?

查看:178
本文介绍了如何在C#中组合字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要组合Stings a, b, c, d。
我尝试将它们放入列表中,然后通过它们解析foreach方法,但无济于事。

I need to make a combinaion of Stings "a" "b" "c" "d". I've tried putting them in a list then parsing a foreach methord through them, but to no avail.

我还能做什么?

推荐答案

我会给你逻辑。

创建 List< String> ,然后继续向其中添加每个字符串。

Create a List<String> and then go on adding each string to it.

List<String> s = new List<String>();  

s.add("a");
s.add("b");
s.add("c");
s.add("d");  

一旦添加了所有字符串,然后在最小和最大索引之间生成一个随机数,如下所示:

Once you added all the strings, then generate a random number between minimum and maximum index like this :

private int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max); 
}  

然后,在循环中使用此数字打印列表中的每个字符串时, 确保,以确保在nex迭代中不重复相同的随机数。

Then, while printing each string in the loop over the List with this number, be sure to check that the same random number is not repeated for the nex iteration.

这篇关于如何在C#中组合字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆