コード例 #1
0
        private static void ShowRefReturnsAndLocals()
        {
            Console.Out.WriteLine($"{nameof(Program.ShowRefReturnsAndLocals)}");
            Console.Out.WriteLine();

            var slowClassList = new SlowList <GiantClass>(100);

            slowClassList[50] = new GiantClass();
            var slowClass1 = slowClassList[50];
            var slowClass2 = slowClassList[50];

            slowClass1.Value1 = 22;
            Console.Out.WriteLine(
                $"{nameof(slowClass2)}.{nameof(slowClass2.Value1)} is {slowClass2.Value1}");

            var slowList    = new SlowList <GiantStruct>(100);
            var slowStruct1 = slowList[50];
            var slowStruct2 = slowList[50];

            slowStruct1.Value1 = 22;
            Console.Out.WriteLine(
                $"{nameof(slowStruct2)}.{nameof(slowStruct2.Value1)} is {slowStruct2.Value1}");

            var fastList = new FastList <GiantStruct>(100);

            // Note, you can type this, but it won't be "ref"
            //var fastStruct1 = fastList[50];
            //var fastStruct2 = fastList[50];

            ref var fastStruct1 = ref fastList[50];
コード例 #2
0
 public void Setup()
 {
     this.slowListData        = new SlowList <GiantStruct>(100000);
     this.slowListData[40000] = new GiantStruct {
         Value1 = 222, Value2 = Guid.NewGuid(), Value3 = 22.2, Value4 = "A bunch of data"
     };
     this.fastListData        = new FastList <GiantStruct>(100000);
     this.fastListData[40000] = new GiantStruct {
         Value1 = 222, Value2 = Guid.NewGuid(), Value3 = 22.2, Value4 = "A bunch of data"
     };
 }