C # means to implement array-wide arrangement by yield

Source: Internet
Author: User

The example in this paper describes the method by which C # implements the array arrangement by yield. Share to everyone for your reference. The specific analysis is as follows:

Any element of M (m≤n) from n different elements, arranged in a certain order, is called an arrangement of extracting m elements from n different elements. All permutations are called when m=n.

static void swap<t> (Ref t A, ref T B) {T t = A; a = b; b = T;} Static ienumerable<int[]> Perm (int[] arr, int pos) {if (pos = = arr. Length) {  yield return arr;} for (int i = pos; i < arr. Length; ++i) {  Swap (ref arr[i], ref arr[pos]);  foreach (Var j in Perm (arr, pos + 1)) yield return J;  Swap (ref arr[i], ref arr[pos]); }}static void Main (string[] args) {foreach (var i in Perm (new int[] {1, 2, 3, 4}, 0)) {  Console.WriteLine (string. Join (",", I.select (J=>j.tostring ()). ToArray ())); }}

I hope this article is helpful to everyone's C # programming.

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
C # means to implement array-wide arrangement by yield

This address: http://www.paobuke.com/develop/c-develop/pbk23088.html






Related Content C # Lossless high quality compressed picture Code C # program (with multiple DLLs) a simple way to merge into an EXE C#6 NULL conditional operator c#ó?μy1é?? ¨?a??? -μ?±3°ü?êìa
C # Design Pattern Series Tutorial-factory method Mode C # Read and write INI file Method C # Basic syntax: As operator use instance C # custom traditional and Simplified Chinese libraries implement a method of converting between traditional and English

C # means to implement array-wide arrangement by yield

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.