New Deck of cards display in a textbox -


  private void getnewdeck_click(object sender, eventargs e)     {        string[] suit = { "c", "d", "h", "s" };         string[] num = { "2", "3", "4", "5", "6", "7", "8", "9", "t", "j", "q", "k", "a" };         (int j = 0; j < 4; j++)         {             (int = 0; < 13; i++)             {                newdecktextbox.text + = (suit[j] , num[i]"\n");             }         }      } 

i trying display new deck of cards in multiline textbox(newdecktextbox) when click button getnewdeck_click button.iam having error newdecktextbox.text line..

the output should

 c2 c3 c4 c5 c6 c7 c8 c9 c10 cj cq ck ca  d2 d3 d4 d5 d6 d7 d8 d9 d10 dj dq dk da  h2 h3 h4 h5 h6 h7 h8 h9 h10 hj hq hk ha  s2 s3 s4 s5 s6 s7 s8 s9 s10 sj sq sk sa 

thanks

this bit better

stringbuilder sb = new stringbuilder(); foreach (string suit in new string[] { "c", "d", "h", "s" }) {   foreach (string value in new string[] { "2", "3", "4", "5", "6", "7", "8", "9", "t", "j", "q", "k", "a" } )   {     sb.append(suit);     sb.append(value);     sb.append(" ");   }   sb.append(environment.newline); } newdecktextbox.text = sb.tostring() 

strings immutable in .net. way build new string every card added textbox, 52 of them "c2 " "c2 c3 " ....

as start manipulating string in loop, stringbuilder way go.

another tip use foreach if can, way if wanted add card e.g. emperor (invented me now), you'd have change loop variables , arrays.

happy learning.

environment.newline line end environent in, automatically copes lf or crlf.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -