结构函数_2

     定义一个Vector3的类(这个类可以用来表示坐标,可以用来表示向量),在里面定义一个Distance方法,用来取得一个向量的长度.

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace 结构体
 7 {
 8     //创建一个Vector3的结构函数
 9     struct Vector3
10     {
11         public float x;
12         public float y;
13         public float z;
14         public double Distance()
15         {
16             return Math.Sqrt(x*x+y*y+z*z);//使用开方需要先调用Math类,然后才能调用Math类中的方法
17         }
18     }
19     class Program
20     {
21         
22 
23         static void Main(string[] args)
24         {
25             Vector3 myMath;
26             myMath.x = 3;
27             myMath.y = 4;
28             myMath.z = 5;
29             Console.WriteLine("向量的长度"+myMath.Distance());
30             Console.ReadKey();
31         }
32     }
33 }
原文地址:https://www.cnblogs.com/jc-1997/p/6074988.html