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 }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值