字符串问题
有3 个句子字符串
A={"a","some","any"};
B={"boy","girl","car"};
C={"go","walk","fly"}
怎样随机在每个字符串中提取一个单词组成句子
我写的,不知是否合理。呵呵
using System;
using System.Collections.Generic;
using System.Text;
namespace cc
{
class Program
{
static void Main(string[] args)
{
string[] A = new string[3] { "a", "some", "any" };
string[] B = new string[3] { "boy", "girl", "car" };
string[] C = new string[3] { "go", "walk", "fly" };
Random rdm = new Random();
int irdm = rdm.Next(0, 3);//取 0 1 2 随机数
string s = A[irdm];//在A数组中取一个元素
irdm = rdm.Next(0, 3);
s = s + " " + B[irdm];//在B数组中取一个元素
irdm = rdm.Next(0, 3);
s = s + " " + C[irdm] + ".";//在C数组中取一个元素
Console.WriteLine("{0}", s);
}
}
}