我是靠谱客的博主 迅速萝莉,这篇文章主要介绍C#基础知识8:struct基础知识,现在分享给大家,希望可以做个参考。

如下

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

namespace StructDemo1
{
    internal class Program
    {
        //定义结构体
        public struct Rect
        {
            public double width;
            public double height;
            //结构的构造函数
            public Rect(double x, double y)
            {
                width = x;
                height = y;
            }
            public double Area()
            {
                return width * height;
            }
        }
        static void Main(string[] args)
        {
            Rect rect1;
            rect1.width = 5;
            rect1.height = 3; 
            Console.WriteLine("矩形面积为:" + rect1.Area());
            Rect rect2 = new Rect(6, 10);
            Console.WriteLine("矩形的面积为:" + rect2.Area());
        }
    }
}

最后

以上就是迅速萝莉最近收集整理的关于C#基础知识8:struct基础知识的全部内容,更多相关C#基础知识8内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(129)

评论列表共有 0 条评论

立即
投稿
返回
顶部