博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一个关于boxing和unboxing的demo
阅读量:4647 次
发布时间:2019-06-09

本文共 1201 字,大约阅读时间需要 4 分钟。

demo 来自 CLR via C#(第三版)

 

View Code
1 static void Main(string[] args) 2         { 3             Point p = new Point(1, 1); 4             Console.WriteLine(p); 5  6             p.Change(2, 2); 7             Console.WriteLine(p); 8  9             Object o = p;10             Console.WriteLine(o);11 12             ((Point)o).Change(3, 3);13             Console.WriteLine(o);14 15             ((IChangeBoxedPoint)p).Change(4, 4);16             Console.WriteLine(p);17 18             ((IChangeBoxedPoint)o).Change(5, 5);19             Console.WriteLine(o);20          }
View Code
1     public interface IChangeBoxedPoint 2     { 3         void Change(Int32 x, Int32 y); 4     } 5  6     public struct Point : IChangeBoxedPoint 7     { 8         private Int32 m_x, m_y; 9         public Point(Int32 x, Int32 y)10         {11             m_x = x;12             m_y = y;13         }14 15         public void Change(Int32 x, Int32 y)16         {17             m_x = x;18             m_y = y;19         }20 21         public override string ToString()22         {23             return string.Format("({0},{1})", m_x, m_y);24         }25     }

 

 

转载于:https://www.cnblogs.com/swanestle/archive/2012/08/20/2647164.html

你可能感兴趣的文章
中文词频统计
查看>>
华为S5024p交换机配端口镜像
查看>>
VirtualBox虚拟机配置CentOS7网络图文详解教程
查看>>
[Asp.net 5] DependencyInjection项目代码分析-目录
查看>>
努比亚(nubia) V18 NX612J 解锁BootLoader 并刷入recovery ROOT
查看>>
SOAP协议初级指南(7)
查看>>
使用 IntraWeb (39) - THttpRequest、THttpReply
查看>>
ImageMagick还是GraphicsMagick?
查看>>
[BZOJ 4571][Scoi2016]美味(主席树)
查看>>
python网络-计算机网络基础(23)
查看>>
Mysql5.7.16安装过程
查看>>
Linux文件查找命令find用法整理(locate/find)
查看>>
20175333曹雅坤实验四《Android程序设计》实验报告
查看>>
max(min)-device-width和max(min)-width的区别
查看>>
geolocation/ 百度地图api Geolocation 定位当前城市信息
查看>>
JAVA基础
查看>>
ruby的optparse使用小记
查看>>
Helper Devise: could not find the `Warden::Proxy` instance on request environment
查看>>
javascript--识别判断浏览器
查看>>
python实现的json数据以HTTP GET,POST,PUT,DELETE方式页面请求
查看>>