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
查看全文
相关阅读:
ccmenu里的位置
【luogu P3346】诸神眷顾的幻想乡(广义 SAM)
Snow的追寻(线段树)(LCA)
【bzoj 4303】数列 / T4(K-D tree)
选课 / T3(组合数)(容斥)
随机游走 / T1(期望)(树形DP)
【luogu P3898】期望异或 / T3 / 大新闻(数位DP)(数学)
【luogu P7295】Paint by Letters P(前缀和)(欧拉公式)(bfs)(对偶图)
【luogu P7294】Minimum Cost Paths P(二分)(单调栈)(斜率)
【luogu P7293】Sum of Distances P(线段树)(图论)
原文地址:https://www.cnblogs.com/downmoon/p/1019250.html
最新文章
11.28
读写cookie
新建DIV的坐标设置
JQuery选择器大全
SQL9:触发器和游标
SQL8:T-SQL
SQL7:CASE语句
SQL6:连接查询
SQL5:联合查询
SQL4:函数
热门文章
SQL3:SQL
动作之CCActionInstant(立即动作)家族
粒子效果
未命名 1
未命名 1
未命名 1
.PIG File
Xcode 4-PBXcp error修复-No such file or directory
Mac OS X 10.7下找不到~/Library/Application Support的解决方案
xcode 高亮
Copyright © 2011-2022 走看看