2016-12-14 1 views
0

코드의 목적은 .txt 파일에서로드 한 다음 임의로 선을로드하여 디스플레이. 나는 그걸 만지작 거 렸고 좀 더 도움이 필요해. 어떤 도움을 주시면 감사하겠습니다. 조정이 필요한 부분은 주석 처리되어 있습니다. 사용할 수있는 다음이 코드를 .txt 파일에서로드하고 무작위로 선을 선택하는 데 도움이 필요합니다.

string[] array = File.ReadAllLines("path"); 

을 그리고 :

using System; 
using System.Collections.Generic; 
using System.Windows.Forms; 
using System.IO; 

namespace EquityPicks 
{ 
    public partial class MainForm : Form 
    { 
     public List<string> appList = new List<string>(7); 

     public MainForm() 
     { 
      InitializeComponent(); 
      loadList(); 
     } 

     public void loadList() // Adjust to load from a text File 
     { 
      appList.Clear(); 
      for(int i =0; i<10; i++) 
      { 
       string text; 
       using (var streamReader = new StreamReader(@"c:\file.txt", Encoding.UTF8)) 
      { 
       text = streamReader.ReadToEnd(); 
      } 
      } 

      nextUpTextBox.Text = getMember(); 
      onDeckTextBox.Text = getMember(); 
      studentsLeftTextBox.Text = appList.Count.ToString(); 
     } 

     public string getMember() // Adjust for Randomness 
     { 
      string member = appList[0]; 
      appList.RemoveAt(0); 
      return member; 
     } 

     void NextButtonClick(object sender, EventArgs e) 
     { 
      if(appList.Count >= 1) 
      { 
       nextUpTextBox.Text = onDeckTextBox.Text; 
       onDeckTextBox.Text = getMember(); 
      } 
      else if (appList.Count == 0) 
      { 
       nextUpTextBox.Text = onDeckTextBox.Text; 
       onDeckTextBox.Text = ""; 
      } 
      else 
      { 
       nextUpTextBox.Text = ""; 
       onDeckTextBox.Text = ""; 
      } 
      studentsLeftTextBox.Text = appList.Count.ToString(); 
     } 

     void ResetButtonClick(object sender, EventArgs e) 
     { 
      loadList(); 
     } 
    } 
} 
+0

이 큰 숙제를 만들 것 그것 같은 소리! – adv12

+0

냄새 :'for (int i = 0; i <10; i ++)'. * 마술 번호 *'10 '은 무엇을 의미합니까? 이전 코드의 –

+0

부분을 삭제했습니다. person이라는 새로운 문자열을 만든 다음 값을 늘려 끝에 숫자를 추가했습니다. –

답변

1

내가 사용하는 것이

new Random().Next(int minValue, int maxValue) 

배열에서 선을 선택합니다.

편집 :

maxValue를 명확히하기는해야 < = 사항 Array.length

+1

'새로운 랜덤(). 다음 (0, 배열. 길이)'이 아니어야합니까? (포함 하한 및 배타적 인 상한) – WiSeeker

+0

,하지만 내 예제에서는 설명서를 보여줍니다 :), 나는 그가 자신의 경계를 설정할 수 있다고 가정했습니다. – Seb

+0

워드 프레스는'새로운 랜덤. 다음 (...)'또는'새로운 랜덤(). –

관련 문제