using System;using System.Linq;publicstaticclassKata{staticint[] result =null;publicstaticint[]Performance(){if(result ==null){
result =newint[4000000];for(var i =0; i < result.Length; i++){
result[i]= i;}}return result;}}
答案4:
using System;using System.Linq;publicstaticclassKata{privatestaticint[] perfCache =null;publicstaticint[]Performance(){if(perfCache ==null){
perfCache = Enumerable.Range(0,4000000).ToArray();}return perfCache;}}
答案5:
using System.Threading.Tasks;publicstaticclassKata{privatestaticint[] Solution =null;publicstaticint[]Performance(){if(Solution ==null){
Solution =newint[4000000];
Parallel.For(0,4000000, i => Solution[i]= i);}return Solution;}}
答案6:
using System;using System.Linq;publicstaticclassKata{staticint count =0;staticint[] array =newint[4000000];publicstaticint[]Performance(){if(count <1){int i =0;do{
array[i]= i++;}while(i < array.Length);
count++;}return array;}}
答案7:
using System;using System.Linq;publicstaticclassKata{privatestaticreadonlyint[] values =GenerateValues();privatestaticint[]GenerateValues(){int[] result =newint[4000000];for(int i =0; i <4000000; i++){
result[i]= i;}return result;}publicstaticint[]Performance()=> values;}
答案8:
using System;using System.Linq;publicstaticclassKata{privatestaticint[] cache;publicstaticint[]Performance(){if(cache ==null){
cache =newint[4000000];for(var i =0; i <4000000; i++)
cache[i]= i;}return cache;}}
答案9:
using System;using System.Linq;publicstaticclassKata{privatestaticint[] cache =null;publicstaticint[]Performance(){if(cache !=null){return cache;}
cache =newint[4000000];for(int i =0; i < cache.Length; i++){
cache[i]= i;}return cache;}}
答案10:
using System;using System.Linq;publicstaticclassKata{privatestaticint[] a;staticKata(){
a =newint[4000000];for(int i =0; i <4000000; i++){
a[i]= i;}}publicstaticint[]Performance(){return a;}}