以前,在看C的数据结构和算法时,结构是经常用到的。
MS在C#中,结构沦为一种点缀。主要还是要有类来实现。因为它毕竟是面象过程时代的产物。。。?
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace ConsoleApplication4 8 { 9 10 class Program 11 { 12 public struct Rect 13 { 14 public double width; 15 public double height; 16 public Rect(double x, double y) 17 { 18 width = x; 19 height = y; 20 } 21 public double Area() 22 { 23 return width * height; 24 } 25 26 static void Main(string[] args) 27 { 28 Rect rect1; 29 rect1.width = 5; 30 rect1.height = 3; 31 Console.WriteLine("矩形面积为: " + rect1.Area()); 32 Rect rect2 = new Rect(4, 6); 33 Console.WriteLine("矩形面积为: " + rect2.Area()); 34 35 Console.Read(); 36 37 } 38 } 39 } 40 }