Esempio n. 1
0
        static async Task Main(string[] args)
        {
            //var s = new DelegateTest1();
            //s.SayHello();

            //var s2 = new DelegateTest2();
            //s2.SayHello();
            //s2.SayHello2();

            //var s3 = new DelegateTest3();
            //s3.SayHello();

            //var s4 = new DelegateTest4();
            //s4.MainSayHello();

            await AsyncTest.Async();

            BoxingAndUnboxing();

            var p  = new Point(10, 20);
            var p1 = p.Point2(0, 0);

            var sp  = new StructPoint(11, 22);
            var sp2 = new StructPoint(11, 22);

            sp = sp2;
        }
Esempio n. 2
0
        /// <summary>
        /// 参考実装。
        /// 構造体にするだけでどれくらい速いか。
        ///
        /// 当たり前だけどダントツで速い。
        /// クラスを構造体に変えただけで、<see cref="GarbageCollection"/>より余裕で1桁速い。
        /// 小さくて頻繁に new して寿命が短いオブジェクトは構造体にしないといけないというのがよくわかる例。
        /// </summary>
        public static (int x, int y) Struct(int loops)
        {
            var p = new StructPoint(1, 2);

            for (int i = 0; i < loops; i++)
            {
                p = new StructPoint(p.Y, p.X + p.Y);
            }
            return(p.X, p.Y);
        }
Esempio n. 3
0
        public void ElementValueType()
        {
            //arrange
            StructPoint[] a = new StructPoint[1000];

            //act
            int x = a[500].X;

            //assert
            Assert.AreEqual(0, x);
        }
Esempio n. 4
0
        public void AssignmentValueTypeInstance()
        {
            StructPoint p1 = new StructPoint();

            p1.X = 7;
            StructPoint p2 = p1;

            Console.WriteLine(p1.X);
            Console.WriteLine(p2.X);

            p1.X = 9;
            Assert.AreEqual(7 + 9, p2.X + p1.X);
        }
        private static void CreateStructCellsThreaded(int cellWidth, int cellHeight, int startX, int startY)
        {
            var Cells = new StructGridCell[RowsCount][];

            Parallel.For(0, RowsCount, i =>
            {
                Cells[i] = new StructGridCell[ColumnsCount];
                for (int j = 0; j < ColumnsCount; j++)
                {
                    var coordinate = new StructPoint(startX + cellWidth * j, startY + cellHeight * i);
                    Cells[i][j]    = new StructGridCell(cellWidth, cellHeight, coordinate);
                }
            });
        }
        private static void CreateStructCells(int cellWidth, int cellHeight, int startX, int startY)
        {
            var Cells = new StructGridCell[RowsCount][];

            for (int i = 0; i < RowsCount; i++)
            {
                Cells[i] = new StructGridCell[ColumnsCount];
                for (int j = 0; j < ColumnsCount; j++)
                {
                    var coordinate = new StructPoint(startX + cellWidth * j, startY + cellHeight * i);
                    Cells[i][j] = new StructGridCell(cellWidth, cellHeight, coordinate);
                }
            }
        }
 public StructGridCell(int width, int height, StructPoint point)
 {
     this.width  = width;
     this.height = height;
     this.point  = point;
 }