Hi everyone,

I'm trying to pass data to managed object arrays. In this case i got no errors also no
correct output. So what's wrong in the code below ?
Please help.

PS. This code writes " MyDataType" on textBox1 ??!

*   MyDataType.h  *
using namespace System;

public ref class MyDataType 

  public: // all are public ok
  int id;
  String ^name; 

  MyDataType() : id(0) {}
  MyDataType(int value) : id(value) {}  
  ~MyDataType() {}

private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) 
array<MyDataType ^> ^arrayObject = gcnew array <MyDataType ^> (5);

arrayObject [0] = gcnew MyDataType;

arrayObject [0]->id = 1;
arrayObject [0]->name = "nut";

// Checking any array object content			 
textBox1->AppendText( Convert::ToString(arrayObject[0]));  


Recommended Answers

All 2 Replies

Your code is "converting" the object at element position 0 (an instance of MyDataType) to a string - but since it's an object, you are getting the type name.

I'm assuming you want "nut" to appear in the text box. If so, the code that does this is:


If you add a "toString" method to your "MyDataType" class, you could change your code to:


Assuming, of course, that your "toString()" method returns a string with the data contained in the "^name" property.

Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.