?? 操作符重載方法.txt
字號:
CLR對操作符重載一無所知,是編程語言定義了每個操作符的含義。
C#操作符號 特珠方法的方法名 推薦的與CLS兼容的方法名
+ op_UnaryPlus Plus
- op_UnaryNegation Negate
~ op_UnaryComplement OnesComplement
++ Op_Increment Increment
。。。
在VB中可以調用C#編譯順生成的類型中的op_Addition方法。
1.test1.vb vbc /t:library test1.vb
Imports System
Public Class VBType
Public Shared Function op_Addition(a as VBType,b as VBType)As VBType
Return Nothing
End Function
End Class
2.test2.cs csc /r:test1.dll test2.cs
using System;
public class CSharpApp
{
public static void Main()
{
VBType vb=new VBType();
vb=VBType.op_Addition(vb,vb);
}
}
C#支持轉換操作符重載。
implicit 不必顯示的轉型
explicit 需要指定顯示的轉型
CLR完全支持一個類型定義多個只有返回值類型差別的方法。
IL支持
C++/C#/VB 不支持
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -