How to initialize Byte^ array?

C

Cat

Hi.
static readonly byte[] Exponent = new byte[] {0x1, 0x0, 0x1 };
This is a C# code. I would like to do the same thing in Managed C++
static array<Byte^>^ Exponent = gcnew array<Byte^>(3) {0x1, 0x0,
0x1 };
But this caused,
error C2440: 'initializing' : cannot convert from 'int' to
'System::Byte ^'
How can I fix this? Please give me a hint.
Thank you.
 
C

Cat

Hi.
   static readonly byte[] Exponent = new byte[] {0x1, 0x0, 0x1 };
This is a C# code. I would like to do the same thing in Managed C++
   static array<Byte^>^ Exponent = gcnew array<Byte^>(3) {0x1, 0x0,
0x1 };
But this caused,
  error C2440: 'initializing' : cannot convert from 'int' to
'System::Byte ^'
How can I fix this? Please give me a hint.
Thank you.

Is it impossible to initialize Byte^ at declaration in MC++?
 
M

Mark Salsbery [MVP]

Cat said:
Hi.
static readonly byte[] Exponent = new byte[] {0x1, 0x0, 0x1 };
This is a C# code. I would like to do the same thing in Managed C++
static array<Byte^>^ Exponent = gcnew array<Byte^>(3) {0x1, 0x0,
0x1 };
But this caused,
error C2440: 'initializing' : cannot convert from 'int' to
'System::Byte ^'


The error message says it all - you can't initialize Byte references with
integers.

It looks like you meant to allocate an array of Bytes, not an array of
Byte^s...

array<Byte>^ Exponent = gcnew array<Byte>(3){0x1, 0x0, 0x1};

Mark
 
C

Cat

Hi.
  static readonly byte[] Exponent = new byte[] {0x1, 0x0, 0x1 };
This is a C# code. I would like to do the same thing in Managed C++
  static array<Byte^>^ Exponent = gcnew array<Byte^>(3) {0x1, 0x0,
0x1 };
But this caused,
 error C2440: 'initializing' : cannot convert from 'int' to
'System::Byte ^'

The error message says it all - you can't initialize Byte references with
integers.

It looks like you meant to allocate an array of Bytes, not an array of
Byte^s...

array<Byte>^ Exponent = gcnew array<Byte>(3){0x1, 0x0, 0x1};

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++


How can I fix this? Please give me a hint.
Thank you.

Thank you for the answer. The ^ symbol is confusing, I just thought ^
was representing that the class was a managed class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top