ITeye博客

ch02 StructTest

kanglecjr · 2009-07-06 11:09 · C# · C · Linq · C++ · C# · Markdown

struct 是 值类型,类 是 引用类型。


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StructTest
{   // 定义 point 结构
    public struct point
    {
        public int x;
        public int y;
    }
    // 定义 Rectangle 结构
    public struct Rectangle
    {

        public point topleft;
        public point topright;
        public point bottomleft;
        public point bottomright;
        public bool used;
    }
    class Program
    {
        static void Main(string[] args)
        {
            // 初始化 Rectangle 结构变量
            Rectangle rec, rc;
            rec.topleft.x = 200;
            rec.topleft.y = 200;
            rec.topright.x = 300;
            rec.topright.y = 200;
            rec.bottomleft.x = 200;
            rec.bottomleft.y = 300;
            rec.bottomright.x = 300;
            rec.bottomright.y = 300;
            rec.used = true;
            rc = rec;

            Console.WriteLine("rc.topleft.x={0}", rc.topleft.x);

            Console.WriteLine("rc.topleft.y={0}", rc.topleft.y);

            Console.WriteLine("rc.topright.x={0}", rc.topright.x);

            Console.WriteLine("rc.topright.y={0}", rc.topright.y);

            Console.WriteLine("rc.bottomleft.x={0}", rc.bottomleft.x);

            Console.WriteLine("rc.bottomleft.y={0}", rc.bottomleft.y);

            Console.WriteLine("rc.bottomright.x={0}", rc.bottomright.x);

            Console.WriteLine("rc.bottomright.y={0}", rc.bottomright.y);

            Console.WriteLine("rc.used={0}", rc.used);

            Console.ReadKey();

        }
    }
}

诚品服饰 英伦男装 无条件退换

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。