---
title: "ch02 StructTest"
author: "kanglecjr"
date: "2009-07-06T11:09:32Z"
tags: ["C", "C#", "C++", "Linq"]
slug: "ch02-structtest"
draft: false
lastmod: "2009-07-06T11:09:32Z"
id: 420670
url: "https://kanglecjr.iteye.com/blog/420670"
---

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

```c#

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();

        }
    }
}

```


[诚品服饰 英伦男装 无条件退换](http://s.click.alimama.com/a/qvYjdTCFlgg=-13358728)