using System; using System.Linq; using System.Collections.Generic; using System.Diagnostics;
namespaceLargeData { publicclassOrderModel { publicstring OrderNumber { get; set; } } publicclassProgram { privatestaticreadonlyint _dataCount = 20000000; publicstaticvoidMain() { var list = new List<OrderModel>(); for (var i = 0; i < _dataCount; i++) { list.Add(new OrderModel { OrderNumber = $"{i + 1}" }); }
Stopwatch sw = new Stopwatch(); sw.Reset(); sw.Start();
var result = list.ToList(); var targetOrderNumber = "20000000"; var targetOrder = list .Where(x => x.OrderNumber == targetOrderNumber) .FirstOrDefault();