最近看到这样一段代码觉得很有意思,记录一下:
using System; using System.Threading;
// 睡眠排序 namespace SleepSort { class SleepSortMainEntence { static void Main (string[] args) { int[] a = new int[] { 123, 243, 32, 443, 72, 3 }; foreach (var item in a) { // 遍历数组 Thread th = new Thread (x => { Thread.Sleep (item * 10); //睡眠时间,时间越短,越不精确 System.Console.WriteLine (item); // 睡完输出 }); th.Start (); //开始线程 } } } }
原文出处:https://innei.ren/posts/programming/SleepSort-C