zoukankan
html css js c++ java
c#中结构的转化示例
c#中结构的转化示例
structconversion.cs
using
System;
struct
RomanNumeral
...
{
public
RomanNumeral(
int
value)
...
{
this
.value
=
value;
}
static
public
implicit
operator
RomanNumeral(
int
value)
...
{
return
new
RomanNumeral(value);
}
static
public
implicit
operator
RomanNumeral(BinaryNumeral binary)
...
{
return
new
RomanNumeral((
int
)binary);
}
static
public
explicit
operator
int
(RomanNumeral roman)
...
{
return
roman.value;
}
static
public
implicit
operator
string
(RomanNumeral roman)
...
{
return
(
"
Conversion not yet implemented
"
;
}
private
int
value;
}
struct
BinaryNumeral
...
{
public
BinaryNumeral(
int
value)
...
{
this
.value
=
value;
}
static
public
implicit
operator
BinaryNumeral(
int
value)
...
{
return
new
BinaryNumeral(value);
}
static
public
implicit
operator
string
(BinaryNumeral binary)
...
{
return
(
"
Conversion not yet implemented
"
;
}
static
public
explicit
operator
int
(BinaryNumeral binary)
...
{
return
(binary.value);
}
private
int
value;
}
class
Test
...
{
static
public
void
Main()
...
{
RomanNumeral roman;
roman
=
10
;
BinaryNumeral binary;
//
Perform a conversion from a RomanNumeral to a
//
BinaryNumeral:
binary
=
(BinaryNumeral)(
int
)roman;
//
Performs a conversion from a BinaryNumeral to a RomanNumeral.
//
No cast is required:
roman
=
binary;
Console.WriteLine((
int
)binary);
Console.WriteLine(binary);
}
}
邀月注:本文版权由邀月和博客园共同所有,转载请注明出处。
助人等于自助!
3w@live.cn
查看全文
相关阅读:
Linux 压缩解压文件
六天玩转javascript:javascript变量与表达式(2)
六天玩转javascript:javascript变量与表达式(1)
HTML5服务器端推送事件 解决PHP微信墙推送问题
signalR制作微信墙 开源
PhpStorm下Laravel代码智能提示
ubuntu下使用nginx部署Laravel
PHP微信墙制作,开源
信鸽推送.NET SDK 开源
14年总结
原文地址:https://www.cnblogs.com/downmoon/p/1019250.html
最新文章
android控件的对齐方式(转)
遇见Vue.js
理论整理(三)
理论整理(五)
理论整理(四)
web典型理论题整理HTML+CSS部分
web典型理论题整理JS部分
纯JS 将table表格导出到excel
input框只能输入整数和浮点数非数字就不输入
jquery.fullPage.js全屏滚动插件教程演示
热门文章
原生JS实现购物车功能
Fiddler + 夜神模拟器 实现网络抓包
SourceTree 这是一个无效源路径/URL的 解决方法
远程计算机或设备不接受连接
PHP操作Redis 含Redis密码验证
生成随机码
redis 抢购秒杀
MySQL 事务回滚
PHP 类的反射
Mysql 优化
Copyright © 2011-2022 走看看