博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
struct 结构体
阅读量:2145 次
发布时间:2019-04-30

本文共 668 字,大约阅读时间需要 2 分钟。

C# 中结构体的定义可以在命名空间下 (namespace) 。

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace CZBKe{    struct Postion    {        // 如果将成员属性设置为私有,在外部将无法访问到该变量        public float x;        public float y;        public float z;        public double GetDistance()        {            return Math.Sqrt(x * x + y * y + z * z);        }    }    class Program    {        static void Main(string[] args)        {            Postion pos1;            pos1.x = 10;            pos1.y = 20;            pos1.z = 30;            Console.WriteLine(pos1.GetDistance());            Console.ReadKey();        }            }}

 

转载地址:http://giegf.baihongyu.com/

你可能感兴趣的文章
Leetcode C++《热题 Hot 100-26》15.三数之和
查看>>
Leetcode C++《热题 Hot 100-28》19.删除链表的倒数第N个节点
查看>>
Leetcode C++《热题 Hot 100-29》22.括号生成
查看>>
Leetcode C++《热题 Hot 100-40》64.最小路径和
查看>>
Leetcode C++《热题 Hot 100-41》75.颜色分类
查看>>
Leetcode C++《热题 Hot 100-42》78.子集
查看>>
Leetcode C++《热题 Hot 100-43》94.二叉树的中序遍历
查看>>
Leetcode C++ 《第175场周赛-1 》5332.检查整数及其两倍数是否存在
查看>>
Leetcode C++ 《第175场周赛-2 》5333.制造字母异位词的最小步骤数
查看>>
Leetcode C++ 《第175场周赛-3》1348. 推文计数
查看>>
Leetcode C++《热题 Hot 100-44》102.二叉树的层次遍历
查看>>
Leetcode C++《热题 Hot 100-45》338.比特位计数
查看>>
读书摘要系列之《kubernetes权威指南·第四版》第一章:kubernetes入门
查看>>
Leetcode C++《热题 Hot 100-46》739.每日温度
查看>>
Leetcode C++《热题 Hot 100-47》236.二叉树的最近公共祖先
查看>>
Leetcode C++《热题 Hot 100-48》406.根据身高重建队列
查看>>
《kubernetes权威指南·第四版》第二章:kubernetes安装配置指南
查看>>
Leetcode C++《热题 Hot 100-49》399.除法求值
查看>>
Leetcode C++《热题 Hot 100-51》152. 乘积最大子序列
查看>>
[Kick Start 2020] Round A 1.Allocation
查看>>