C ++CLI and C # common syntax comparison (transfer)

xiaoxiao2021-03-06  102

(Transfer) zeng yi's blog

Kenny Kerr is named C : The Most Powerful Language for .NET Framework Programming

The comparison table in the article is very clearly demonstrating the simplicity of the design of the version 2 language and is close to the native language. Worth reference:

description

C / CLI

C #

Create a reference type object

Referencetype ^ h = gcnew reference;

Referencetype h = new referenceType ();

Create value type object

ValueType V (3, 4);

ValueType v = new valuepe (3, 4);

Quote type on the stack

Referencetype h;

N / a

Call Dispose method

Referencetype ^ h = gcnew reference;

Delete H;

Referencetype h = new referenceType ();

(IDisposable) h) .dispose ();

Implement Dispose method

~ TypeName () {}

Void idisposable.dispose () {}

Implement Finalize method

! Typename () {}

~ TypeName () {}

Boxing

INT ^ h = 123;

Object h = 123;

Unboxing

INT ^ Hi = 123;

INT C = * Hi;

Object h = 123;

INT i = (int) h;

Define reference type

Ref class referencetype {};

Ref struct referencetype {};

Class Referencetype {}

Definition value type

Value Class valuePE {};

Value struct valueetype {};

Struct valuepe {}

Use attribute

H.prop = 123;

INT V = H.Prop;

H.prop = 123;

INT V = H.Prop;

Define properties

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;}}

转载请注明原文地址:https://www.9cbs.com/read-105584.html

New Post(0)