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