Thursday, January 19, 2006

Array var in Managed(.Net) C++

In managed C++, define an array variable for a managed class, in syntax, is different from standard C/C++. For example,

using System::Drawing;
array<PointF, 1>^ pointsF = gcnew array<PointF, 1>(100);
// PointF pointsF[100]; // is wrong
// PointF pointsF[] = gcnew PointF[100]; // is wrong
pointsF[0].X = 11.23f;
pointsF[0].Y = 0.54f;

where PointF is a structure defined in System::Drawing namespace.

For String class, you have define an array of String as:

array<String^, 1>^ s = gcnew array<String^, 1>(10);
//String^ s[] = gcnew String^[10]; // wrong again

The general format to define an array of type is:

[qualifiers] [cli::]array<[qualifiers]type1[, dimension]>^ var =
gcnew [cli::]array<type2[, dimension]> (val[,val...])

See MSDN on Array Keyword


lewismarks5437 said...

I read over your blog, and i found it inquisitive, you may find My Blog interesting. So please Click Here To Read My Blog

k0ety68x said...

Get any Desired College Degree, In less then 2 weeks.

Call this number now 24 hours a day 7 days a week (413) 208-3069

Get these Degrees NOW!!!

"BA", "BSc", "MA", "MSc", "MBA", "PHD",

Get everything within 2 weeks.
100% verifiable, this is a real deal

Act now you owe it to your future.

(413) 208-3069 call now 24 hours a day, 7 days a week.