Basic operations on the array of instance 365 (11) --------- (1)

Source: Internet
Author: User

1. Obtain the number of rows and columns of a two-dimensional array,

Ii. Code
Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. windows. forms; namespace ArrayRank {public partial class Frm_Main: Form {public Frm_Main () {InitializeComponent ();} private string [,] G_str_array; // define the array type variable private Random G_Random_Num = new Random (); // generate the Random number object private void btn_GetArray _ Click (object sender, EventArgs e) {/* parameter minValue type: lower bound of the random number returned by System. Int32 (this lower bound value is recommended for random numbers ). MaxValue type: the upper bound of the random number returned by System. Int32 ). MaxValue must be greater than or equal to minValue. Return Value Type: System. Int32 a 32-bit signed integer greater than or equal to minValue and less than maxValue. That is, the returned value range includes minValue but not maxValue. If minValue is equal to maxValue, minValue is returned. */Txt_display.Clear (); // clear the control string G_str_array = new string [// randomly generate a two-dimensional array G_Random_Num.Next (2, 10), G_Random_Num.Next (2, 10)]; lab_Message.Text = string. format ("an array of {0} row {1} columns is generated",/* GetUpperBound parameter dimension type: System. the dimension of the Int32 array starting from scratch. The upper limit must be determined. Return Value Type: Index of the last element of the dimension specified in the System. Int32 array, or-1 (if the specified dimension is null ). */G_str_array.GetUpperBound (0) + 1, // GetUpperBound (0) returns the upper limit of the First-dimensional Index of the Array, and GetUpperBound (Rank-1) returns the upper limit of the last one-dimensional Index of the Array. Obtain the number of rows in the array G_str_array.GetUpperBound (1) + 1); // obtain the number of columns in the array DisplayArray (); // call the display array method} private void DisplayArray () {// use the cyclic value for (int I = 0; I <G_str_array.GetUpperBound (0) + 1; I ++) {for (int j = 0; j <G_str_array.GetUpperBound (1) + 1; j ++) {G_str_array [I, j] = I. toString () + "," + j. toString () + "" ;}}// use the cyclic output for (int I = 0; I <G_str_array.GetUpperBound (0) + 1; I ++) {for (int j = 0; j <G_str_array.GetUpperBound (1) + 1; j ++) {txt_display.Text + = G_str_array [I, j];} txt_display.Text + = Environment. newLine ;}}}}
3. Search for elements in the array based on specified conditions,

4. Code
Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. windows. forms; namespace FindStr {public partial class Frm_Main: Form {public Frm_Main () {InitializeComponent ();} private string [] G_str_array; // define the string array FIELD private void Frm_Main_Load (object sender, EventArgs e) {G_str_array = new string [] {// Assign a value to the string array field "", "C # programming Dictionary", "C # example ", "C # example "}; for (int I = 0; I <G_str_array.Length; I ++) // loop output string {lab_Message.Text + = G_str_array [I] + "\ n ";}} private void txt_find_TextChanged (object sender, EventArgs e) {if (txt_find.Text! = String. Empty) // checks whether the query string is null {/* Array. FindAll type parameter T Array element type. Parameter array type: T [] The one-dimensional Array from scratch to be searched. Match type: System. Predicate <T>, which defines the conditions for the elements to be searched. Return Value Type: T [] This Array is used if an Array where all elements match the conditions defined by the specified predicate is found. Otherwise, it is an empty Array. */String [] P_str_temp = Array. FindAll // use the FindAll method to find the corresponding string (G_str_array, (s) => s. Contains (txt_find.Text); // represents a method. () Is the parameter of this method, followed by the return value of the method. If (P_str_temp.Length> 0) // determines whether the corresponding string {txt_display.Clear (); // clears the control string foreach (string s in P_str_temp) // Add the string {txt_display.Text + = s + Environment to the control. newLine ;}} else {txt_display.Clear (); // clear the control string txt_display.Text = "no record found"; // the message "no record found"} else {txt_display.Clear (); // clear the string in the control }}}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.