栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何为班级提供自定义演员表支持?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何为班级提供自定义演员表支持?

您需要使用

implicit
explicit
取决于您是否希望用户强制转换它,或者是否希望它自动发生,从而覆盖转换运算符。通常,一个方向将始终有效,这是您使用的地方
implicit
,而另一个方向有时会失败,这是您使用的地方
explicit

语法如下:

public static implicit operator dbInt64(Byte x){    return new dbInt64(x);}

要么

public static explicit operator Int64(dbInt64 x){    if (!x.defined)        throw new DataValueNullException();    return x.iVal;}

以您的示例为例,从您的自定义类型中说(

MyType
->
byte[]
将始终有效):

public static implicit operator byte[] (MyType x){    byte[] ba = // put pre here to convert x into a byte[]    return ba;}

要么

public static explicit operator MyType(byte[] x){    if (!CanConvert)        throw new DataValueNullException();    // Factory to convert byte[] x into MyType    MyType mt = MyType.Factory(x);    return mt;}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/576130.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号