C#之结构体和类1

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

namespace Practice805_3
{
    class Program
    {
        static void Main(string[] args)
        {
            StructFirst first = new StructFirst();
            first.x = 1;
            first.y = 2;
            Console.WriteLine("x         " + first.x);
            Console.WriteLine("y         " + first.y);

            StructFirst first2 = new StructFirst(8, 8);
            Console.WriteLine("结果是{0},and  {1}", first2.x, first2.y);

            Console.ReadLine();
        }
    }
    /**
     * 第一个结构体的建立
     * */
    struct StructFirst
    {
        public double x;
        public double y;

        public StructFirst(double x, double y)
        {
            this.x = x;
            this.y = y;
        }
    }
}

才发现,这结构体霸气啊,居然能够有无参的构造方法,并且永远不会被其他的构造方法给取缔,而且C#中还强制规定不能够创建没有参数的结构体。c#

亲,仔细研究结构体和类的区别,以及他们应用场合,会有不少有意思的地方!this

相关文章
相关标签/搜索