Home > Net >  C #, the split method to obtain the user two Numbers separated by Spaces, the array is empty, what i
C #, the split method to obtain the user two Numbers separated by Spaces, the array is empty, what i

Time:11-29

The user to enter two Numbers, separated by Spaces, I use the split method writes, debugging find yes array is empty, cause I can't for the next step, what reason is this? , every brother please mention I am a novice, thank you!
The static void Main (string [] args)
{
String s=Console. ReadLine ();
String [] x=s.S plit (new char [] {'}, StringSplitOptions. RemoveEmptyEntries;
Int. Price=the Convert ToInt32 (x [0]);
Int discount=the Convert. ToInt32 (x [1]);
Double newPrice=price * (discount/100);
String k=newPrice. ToString ();
Console. WriteLine (k);
//the Console. WriteLine (String Format (" {0: N2} ", k));
The Console. ReadKey ();
}

CodePudding user response:

Post your debug screen, whether you in the watch window or debug debugging command window?

CodePudding user response:

Programming will be subject to testing, rather than pure entangled what logic to ask "why?" .

CodePudding user response:

Var userData="https://bbs.csdn.net/topics/aa bb cc dd ee";
Var arr=userData. The Split (");
{foreach (var STR in arr)
Console. WriteLine (STR);
//if you want to turn int, you can use the var I=int. Parse (STR);
//on the safe side, you can use the int. J TryParse (), the reference function prototype, here not wordy.
}

CodePudding user response:


Bosses, the picture is debugging, you see, I see a lot of online example, to now also didn't want to understand

CodePudding user response:

Power on int price=the Convert. ToInt32 (x [0]);
Check the value of s

CodePudding user response:

reference 5 floor xuzuning reply:
power on int price.=the Convert ToInt32 (x [0]);
Check the value of s

I specialized in the console output s, it is to get my input,

CodePudding user response:

reference 5 floor xuzuning reply:
power on int price.=the Convert ToInt32 (x [0]);
Check the value of s

Followed by x have value, but the price is 0
  •  Tags:  
  • C#