class Digit
{
public Digit(double d) { val = d; }
public double val;
// ...other members // User-defined conversion from Digit to double
public static implicit operator double(Digit d)
{
return d.val;
}
// User-defined conversion from double to Digit
public static implicit operator Digit(double d)
{
return new Digit(d);
}
} class Program
{
static void Main(string[] args)
{
Digit dig = new Digit(7);
//This call invokes the implicit "double" operator
double num = dig;
//This call invokes the implicit "Digit" operator
Digit dig2 = 12;
Console.WriteLine("num = {0} dig2 = {1}", num, dig2.val);
Console.ReadLine();
}
}

  

implicit operator的更多相关文章

  1. 操作符(运算符)重载 或者叫 二元运算符 operator + 与 转换式操作符 implicit operator explicit operator

    static void Main(string[] args) { rational r1 = new rational(5); rational r2 = new rational(51); rat ...

  2. c#自定义类型的转换方式operator,以及implicit(隐式)和explicit (显示)声明

    https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/explicit https://docs.mic ...

  3. operator、explicit与implicit

    说这个之前先说下什么叫隐式转换和显示转换 1.所谓隐式转换,就是系统默认的转换,其本质是小存储容量数据类型自动转换为大存储容量数据类型. 例如:float f = 1.0: double d=f:这样 ...

  4. C#中转换运算符explicit、implicit、operator、volatile研究

    C#中的这个几个关键字:explicit.implicit与operator,估计好多人的用不上,什么情况,这是什么?字面解释:explicit:清楚明白的;易于理解的;(说话)清晰的,明确的;直言的 ...

  5. (二) operator、explicit与implicit 操作符重载

      有的编程语言允许一个类型定义操作符应该如何操作类型的实例,比如string类型和int类型都重载了(==)和(+)等操作符,当编译器发现两个int类型的实例使用+操作符的时候,编译器会生成把两个整 ...

  6. (一) operator、explicit与implicit 操作符重载

                               原文地址:  Click Here 操作符重载必须用public static 应为操作符是用来操作实例的. operator operator ...

  7. 可空类型(Nullable<T>)及其引出的关于explicit、implicit的使用

    问题一:Nullable<T>可赋值为null 先看两行C#代码 int? i1 = null; int? i2 = new int?(); int? 即Nullable<int&g ...

  8. 显示转换explicit和隐式转换implicit

    用户自定义的显示转换和隐式转换 显式转换implicit关键字告诉编译器,在源代码中不必做显示的转型就可以产生调用转换操作符方法的代码. 隐式转换implicit关键字告诉编译器只有当源代码中指定了显 ...

  9. C#类型转换运算符之 explicit implicit

    类型转换运算符 explicit和implicit用于声明用户定义的类型转换运算符,如果可以确保转换过程不会造成数据丢失,则可使用这两个关键字在用户定义的类型和其他类型之间进行转换. explicit ...

随机推荐

  1. AIM Tech Round 3 (Div. 2) A B C D

    虽然打的时候是深夜但是状态比较好 但还是犯了好多错误..加分场愣是打成了降分场 ABC都比较水 一会敲完去看D 很快的就想出了求0和1个数的办法 然后一直wa在第四组..快结束的时候B因为低级错误被h ...

  2. ThinkPHP 3.2.3 简单后台模块开发(二)RBAC

    RBAC(Role-Based Access Controll)基于角色的访问控制 在 ThinkPHP3.2.3 中 RBAC 类位于 /ThinkPHP/Library/Org/Util/Rbac ...

  3. nginx服务器状态监控

    Nginx开启监控需在编译时加入with-http_stub_status_module,查看当前Nginx编译参数:/usr/local/nginx/sbin/nginx -V 1.以二级目录方式开 ...

  4. Android开发常见问题系列之一:eclipse中adb.exe启动失败或者无法启动

    这种情况下大多数是因为存在kadb.exe在执行,或者adb.exe端口被占用. 1,检查是否存在kadb.exe程序正在执行 打开任务管理器,打开详细信息,按照字母顺序找到kadb.exe,结束进程 ...

  5. TF-IDF 文本相似度分析

    前阵子做了一些IT opreation analysis的research,从产线上取了一些J2EE server运行状态的数据(CPU,Menory...),打算通过训练JVM的数据来建立分类模型, ...

  6. jQuery的$.get和$.ajax函数对比

    $.get较为简便,但在精细控制上乏力$.get(    url, // 请求的地址    {url:url,remark:remark},// 请求参数    function(data,textS ...

  7. linux pptpd账号同时登录的问题

    最近搞了个云主机搭建个VPN服务器给自己用, 特别是在公共场所的wifi上网时, 很多APP, 或者网站是没有https的, 所以为了保证信息(主要是账号密码)的安全, 搭个私有vpn还是很有必要的. ...

  8. 【转】HTTP 头部解释,HTTP 头部详细分析,最全HTTP头部信息

    HTTP 头部解释 ========================================================================================== ...

  9. Gradle Cheat Sheet

    加快编译速度 使用 gradle 2.4 及以上版本 ~/.gradle/gradle.properties 加入如下配置 org.gradle.daemon=true org.gradle.jvma ...

  10. C#窗体WinForm 文件操作

    文件及文件夹操作 C/S:WinForm可以操作客户端文件 Client ServerB/S:浏览器服务 Brower Server 命名空间:using system .IO; 1. File类:文 ...