C#中结构数据类型的使用
生活随笔
收集整理的這篇文章主要介紹了
C#中结构数据类型的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
以前,在看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 }轉載于:https://www.cnblogs.com/aguncn/archive/2013/05/05/3060602.html
總結
以上是生活随笔為你收集整理的C#中结构数据类型的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jetty 切换log4j日志接口
- 下一篇: 通讯三要素学习笔记