C++/CLI与C#常用语法对比(转)
来源:互联网 发布:怎么找淘宝客服兼职 编辑:程序博客网 时间:2024/04/29 17:03
(转)Zeng Yi's Blog
Kenny Kerr 一篇名为C++: The Most Powerful Language for .NET Framework Programming 文章中的对比表,十分清晰的展示了版本2语言中设计的简洁和与原生语言的接近。值得参考:
描述 | C++/CLI | C# |
创建引用类型的对象 | ReferenceType^ h = gcnew ReferenceType; | ReferenceType h = new ReferenceType(); |
创建值类型的对象 | ValueType v(3, 4); | ValueType v = new ValueType(3, 4); |
引用类型在堆栈上 | ReferenceType h; | N/A |
调用Dispose方法 | ReferenceType^ h = gcnew ReferenceType; delete h; | ReferenceType h = new ReferenceType(); ((IDisposable)h).Dispose(); |
实现Dispose方法 | ~TypeName() {} | void IDisposable.Dispose() {} |
实现Finalize 方法 | !TypeName() {} | ~TypeName() {} |
装箱(Boxing) | int^ h = 123; | object h = 123; |
拆箱(Unboxing) | int^ hi = 123; int c = *hi; | object h = 123; int i = (int) h; |
定义引用类型 | ref class ReferenceType {}; ref struct ReferenceType {}; | class ReferenceType {} |
定义值类型 | value class ValueType {}; value struct ValueType {}; | struct ValueType {} |
使用属性 | h.Prop = 123; int v = h.Prop; | h.Prop = 123; int v = h.Prop; |
定义属性 | property String^ Name | string Name |
- C++/CLI与C#常用语法对比
- C++/CLI与C#常用语法对比(转)
- Objective-C语法快速参考 [与C#对比]
- C#与C++/CLI混合编程
- C#与C++/CLI混合编程
- Java与C#语法对比及转换
- Java与C#语法对比及转换
- VB.NET与C#语法对比
- VB.NET 、Java 与 C# 语法对比。
- shell 语法与C语言对比
- shell 语法与C语言对比
- shell 语法与C语言对比
- shell 语法与C语言对比
- C++/CLI C#
- c++/cli调用c#
- C++/CLI 调用 C#
- C++/Cli语言语法总结
- CLI与C#比较
- 整理了一下以前的诗
- 每个开发人员现在应该下载的十种必备工具
- 昆明之行
- java文件操作大全
- 脚本加密与解密
- C++/CLI与C#常用语法对比(转)
- 用C宏写的泛型栈
- transaction across server
- Asp.net中的页面乱码的问题
- XU安全组核心人员招收条件
- 智能客户端相关文章及资源:
- 关于无法创建aspx.web项目的解决办法
- 欢迎hua@XUST加入XU安全组!
- DataSet or DataReader?