안녕하세요 여러분, 6 개의 문자열을 임의의 반복없이 6 개의 버튼으로 6 개의 문자열을 무작위로 배포하고 싶습니다. 그게 내가 어떤 종류의 셔플을하고 그것을 배포하고 싶지만 중복되지 않습니다 각 버튼은 고유 문자열을 보유합니다. 사람이 :) 좋은 것입니다 코드를 게시 할 수 있다면 감사C# 반복없이 문자열을 무작위로 배포
class Card_Deck
{
public Random r;
public string ReceiveCards()
{
List<string> cards = new List<string>();
cards.Add("♣ King");
cards.Add("♦ King");
cards.Add("♥ King");
cards.Add("♠ King");
cards.Add("♣ Jack");
cards.Add("♦ Jack");
int index = r.Next(cards.Count);
var card = cards[index];
cards.RemoveAt(index);
return card;
}
}
}
이 기본 폼
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Card_Deck cd = new Card_Deck() { r = new Random(DateTime.Now.Millisecond) };
button1.Text = cd.ReceiveCards();
button2.Text = cd.ReceiveCards();
button3.Text = cd.ReceiveCards();
button4.Text = cd.ReceiveCards();
button5.Text = cd.ReceiveCards();
button6.Text = cd.ReceiveCards();
}
}
}
우리는 코드 공장은 아니다? 너 뭐 해봤 니? 어디서 붙어 있니? 우리는 스스로를 도울 수없는 사람들을 도울 수 없습니다. – zellio
죄송하지만 그 시간에 코드를 저장할 수 없지만 이제는 지금 나를 도와주세요. –