結構實例化,結構實例
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace Test08
7 {
8 class Program
9 {
10 //public struct Round//定義一個圓形結構
11 //{
12 // public double r;//圓形的半徑
13 // /// <summary>
14 // /// 計算圓形面積
15 // /// </summary>
16 // /// <returns>圓形面積</returns>
17 // public double Area()
18 // {
19 // return Math.PI * r * r;
20 // }
21 //}
22 //static void Main(string[] args)
23 //{
24 // Round myRound;//實例化圓形結構
25 // myRound.r = 5;//為圓半徑賦值
26 // Console.WriteLine("圓形面積為:" + myRound.Area());
27 //}
28 public struct yuan
29 {
30 public double r;
31 public double Area()
32 {
33 return Math.PI * r * r;
34 }
35 }
36 public static void Main(string[] args)
37 {
38 yuan mianji;//結構實例化
39 mianji.r = 1;
40 Console.WriteLine( mianji.Area());
41 }
42 }
43 }