Requirements:
There is a picture on the software, which is hidden by default. The user enters a social Security number (131226198105223452) in the text box, clicks the button, and displays the picture if it is older than 18 years old.
Knowledge Points:
take the current year, Date time
The function that needs to be
function One:
String string. Substring (int startindex,int length) (+1 overloads)
Retrieves a string from this instance. SUBSTRING starts at the specified character position and has the specified length
Abnormal:
System.ArgumentOutOfRangeException
Function Two:
int Convert.ToInt32 (string value) (+18 overloads)
the designation of the number The System.String representation is converted to an equivalent 32-bit signed integer
Exceptions:
System.FormatException
system.overflowexception
Function Three:
struct System.DateTime
represents a moment in time, usually expressed as a date and time of day.
The source code is as follows:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespacePicture Display { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidButton1_Click (Objectsender, EventArgs e) { stringID Number =TextBox1.Text; /*string String. Substring (int startindex,int length) (+1 overloads) * Retrieves a string from this instance. The substring starts at the specified character position and has the specified length * Exception: * system.argumentoutofrangeexception */ stringStryear= ID number. Substring (6,4); /*int Convert.ToInt32 (string value) (+18 overloads) * Converts the specified System.String representation of a number to an equivalent 32-bit signed integer * exception: * System.FormatException * System.OverflowException*/ intYear =Convert.ToInt32 (stryear); /*struct System.DateTime * Represents a moment in time, usually expressed as a date and time of day. */ if(Datetime.now.year-year > -) {picturebox1.visible=true; } Else{picturebox1.visible=false; } } }}
Run: