惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
宝玉的分享
宝玉的分享
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
量子位
Blog — PlanetScale
Blog — PlanetScale
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
D
Docker
罗磊的独立博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
IT之家
IT之家
MyScale Blog
MyScale Blog
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - On the way

做产品16年,我有9条心得--百度贴吧前负责人 toB的产品经理和toc产品经理区别 Stack overflow 编译能通过,运行时出现Stack overflow VC2008操作Excel2007总结 C++中使用DOM写XML文档 VC++ MSXML创建XML文件以及对XML文档解析 MFC中的MainFrame Dlg,App,Doc,View的关系 于typedef的用法总结 理解lvalue和rvalue 讲讲volatile的作用 利用C++/CLI 封装Native C++ 提升.NET web game性能 规格单位换算 C/C++中宏使用总结 Working with XML in a Classic COM Application - On the way 位图和矢量图区别 WIKI扫盲手册 C#的显式接口和隐式接口 软件设计的七大原则 ASP.NET下MVC设计模式的实现
C++/CLI与C#常用语法对比
On the way · 2011-11-16 · via 博客园 - On the way

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^ get()
    {
        return m_value;
    }
    void set(String^ value)
    {
        m_value = value;
    }
}

string Name
{
    get
    {
        return m_name;
    }
    set
    {
        m_name = value;
    }
}