使用缓存行提供效率
public class T { //private long p1,p2,p3,p4,p5,p6,p7; public long x = 0L;// 8bytes //private long p9, p10, p11, p12, p13, p14, p15; } public static T[] arr = new T[2]; private const long count = 10_0000_0000L; static void Main(string[] args) { arr[0] = new T(); arr[1] = new T(); var st = new Stopwatch(); st.Start(); Thread thread1 = new Thread(() => { for (long i = 0; i < count; i++) { arr[0].x = i; } }); Thread thread2 = new Thread(() => { for (long i = 0; i < count; i++) { arr[1].x = i; } }); thread1.Start(); thread2.Start(); st.Stop(); Console.WriteLine(st.ElapsedMilliseconds);//84 180(不加前面) Console.ReadKey(); }