Function: Cumulative calculation is realized.
Knowledge Points:
BOOL Int. TryParse (string s,out int result) (+1 overloads)
Converts the string form of a number to its equivalent 32-bit valid signed integer, a return value that indicates whether the operation succeeded.
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceAccumulator { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidButton1_Click (Objectsender, EventArgs e) { stringS1 = TextBox1.Text;//text box One of the input contents is stored in the string S1 strings2 = TextBox2.Text;//text box One of the input contents is stored in the string S1 intI1,i2; /*BOOL Int. TryParse (string s,out int result) (+1 overload) * Converts the string form of a number to its equivalent 32-bit valid signed integer, a return value that indicates whether the operation succeeded. */ if(int. TryParse (S1, outi1) = =false)//text box An input content string S1 converted to integer data i1{MessageBox.Show ("first number format Error!!! "); return; } if(int. TryParse (S2, outi2) = =false)//text box An input content string S1 converted to integer data i2{MessageBox.Show ("Second number format Error!!! "); return; } if(I1 >= I2)//Check for errors{MessageBox.Show ("The second number must be greater than the first number");//set a breakpoint in the wrong place to see the value of the relevant variable. return; } intsum=0; for(inti = I1; I <= i2; i++) {sum= Sum +i; } TextBox3.Text= convert.tostring (sum);//Assign the computed and assigned values to the text box three } }}
Program:
Software: Http://pan.baidu.com/s/1bnq256B