Home > Net >  Asking our bosses!!!!!! - c # for loop
Asking our bosses!!!!!! - c # for loop

Time:10-14

How to use a for loop out four digits you type in the text box, and determine whether repeat if repeat the tip, can't enter duplicate Numbers

CodePudding user response:

Onkeypress?
Can only input Numbers?
Then the input and output?

CodePudding user response:

Not, is to write a small program, judge repetition is written in the button1_click, then run the input Numbers, then judge
On the output,

CodePudding user response:

 
Private void Button1_Click (object sender, EventArgs e)
{
If (textBox1. Text. Length!
=4){
MessageBox. Show (" length is wrong ");
return;
}

For (var I=0; I & lt; 3; I++)
{
For (var j=I + 1; J & lt; 4. J++)
{
If (textBox1. Text. The Substring (I, 1)==textBox1. Text. The Substring (j, 1))
{
MessageBox. Show (" repeat ");
return;
}
}
}
}

CodePudding user response:

After introducing the linq, tocharArray distinct, obtain the count compared with 4 can,

CodePudding user response:

Not necessarily use the for, finally or character, and character of operation,

CodePudding user response:

Var t=textBox1. Text. ToCharArray ().
If (t.G roupBy (p=& gt; P). The Count (a=& gt; A.C mount () & gt; 1) & gt;
=1){
//repeat
}

CodePudding user response:

Very thank you bosses of wisdom! ????

CodePudding user response:

In fact, I just into the line, can simple point to keep it simple, I thank you very much,,,
  •  Tags:  
  • C#
  • Related