C # Converts a string array to an int array and gets the maximum minimum value

Source: Internet
Author: User

1. Converting a string array to an int array

string[] input = {"1","2","3","4","5","6","7","8","9" };int[] output = array.convertall<string,int> (Input,Delegate(strings) {return int. Parse (s); });

Attention:

Use the static generic method ConvertAll in the array class to convert.

Delegate (string s) {return int. Parse (s); This sentence means: Establish an anonymous delegate, the method body associated with the delegate is: return int. Parse (s); Casts each string in the array to reshape and returns the add to output.

2. Sorting

Method One: Use the sort () method of ArrayList

usingSystem.Collections;int[] arr = {2,4,5,6,6, -, the, the, the,669,569 }; ArrayList List=NewArrayList (arr); list. Sort ();intmin = Convert.ToInt32 (list[0]);intmax = Convert.ToInt32 (list[list. Count-1]); Console.WriteLine ("Maximum"+ Max +"Minimum:"+min);


Method Two: (If the values in the array are less than a, this does not apply)

int a=0; b=0;  for (int i=0; i<array.length;i++) {    a>a[i]? ( B=A):(b=a[i]), as long as the round for loop can derive the maximum value, the same as the minimum value.}

C # Converts a string array to an int array and gets the maximum minimum value

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.