我让程序获得长度在10到12之间的随机单词。 如何改变我得到的随机单词并将其分成12个标签上的字母???
string cs = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename= C:\Users\Pavle\Documents\Visual Studio 2015\Projects\Test slagalica\Test slagalica\Slagalica-DB.mdf;Integrated Security=True";
string queryString = "SELECT * FROM table1 WHERE LEN(Reci) >=10 AND LEN(Reci) <=12 ORDER BY NEWID()";
using (SqlConnection connection = new SqlConnection(cs))
{
SqlCommand mycommand = new SqlCommand(queryString, connection);
try
{
connection.Open();
string word = (string)mycommand.ExecuteScalar();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
答案 0 :(得分:1)
我创建了标签,但我不知道如何随机播放单词 点击按钮它应该在其他标签上显示字母!!!
Random rnd = new Random();
string word = "HelloWorld2016";
var result = word.OrderBy(x => rnd.Next()).ToArray();//your word is shuffled
label1.Text = result[0]; //and so on.
您可以使用Random
和OrderBy
。