C # tips (1) on Array Conversion

Source: Internet
Author: User
C # tips (1) on Array Conversion

I found that my memory is getting worse and worse now. Just in case you begin to record some tips on C.

Array conversion. This technique is rarely used for our purposes, because this type of data conversion problem is often blocked during interface definition. But it will happen occasionally.

The array. convertall method of c # provides such a conversion. For example, we need to convert an int-type array to a string array. We can write it like this.

Main ()

{

Int [] iarray = {1, 2 };

String [] strarray = array. convertall (iarray, new converter <int, string> (inttostring ));

}

 

Public static string inttostring (INT argitem)
{
Return argitem. tostring ();
}

In fact, convertall calls the inttostring conversion function through delegation during conversion, and converts the type of each variable in the array.

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.