本文共 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/