Structure instantiation, structure instance
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 // define a circular structure 11 // {12 // public double r; // the radius of the circle is 13 //// <summary> 14 //// calculate the circular area by 15 //// </summary> 16 //// <returns> circular Area </returns> 17 // public double Area () 18 // {19 // return Math. PI * r; 20 //} 21 //} 22 // static void Main (string [] args) 23 // {24 // Round myRound; // instantiate the circular structure 25 // myRound. r = 5; // assign a value of 26 to the circle radius // Console. writeLine ("circular area:" + myRound. area (); 27 //} 28 public struct yuan 29 {30 public double r; 31 public double Area () 32 {33 return Math. PI * r; 34} 35} 36 public static void Main (string [] args) 37 {38 yuan mianji; // structure instantiation 39 mianji. r = 1; 40 Console. writeLine (mianji. area (); 41} 42} 43}