Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从数组中选择随机变量_C#_Arrays_Visual Studio_Synthesizer - Fatal编程技术网

C# 从数组中选择随机变量

C# 从数组中选择随机变量,c#,arrays,visual-studio,synthesizer,C#,Arrays,Visual Studio,Synthesizer,我目前正在尝试用3个可能的文本值(如hi、hello和hey)制作一个数组,对于语音合成器,我只是不知道如何让它随机说出其中一个值?使用以下代码: string[] words=new string[]{"hi","Hello","Hey"}; Random r = new Random(); int i= r.Next(0, 2); string randomWord= words[i]; 在发布问题之前,请考虑做一个小的搜索,这些类型的基本问题已经被人问过了!你可以去看看,然后投票选出

我目前正在尝试用3个可能的文本值(如hi、hello和hey)制作一个数组,对于语音合成器,我只是不知道如何让它随机说出其中一个值?

使用以下代码:

string[] words=new string[]{"hi","Hello","Hey"};

Random r = new Random();
int i= r.Next(0, 2);

string randomWord= words[i];

在发布问题之前,请考虑做一个小的搜索,这些类型的基本问题已经被人问过了!你可以去看看,然后投票选出一个适合你的答案!是的,我不知道为什么我好像没有遇到