tags:

views:

185

answers:

2

Hi in the second line while trying to convert from object to String array it shows compile time error as

'System::String ^' : a native array cannot contain this managed type

'initializing' : cannot convert from 'System::String ^' to 'System::String ^[]'

code:

RegistryKey ^rk = Registry::LocalMachine->OpenSubKey("SOFTWARE\\Microsoft\\Microsoft SQLServer");
String ^instances[] = (String^)rk->GetValue("InstalledInstances");

How to fix this .... Thanks in advance.

A: 

Change the last line to

String ^ instances = (String^)rk->GetValue("InstalledInstances");

(note the absence of brackets). If the key contains a multistring, use

array<String^>^ instances
    = (array<String^>^)rk->GetValue("InstalledInstances");

See the documentation for RegistryKey.GetValue for more information.

avakar
yes man excellent it working fine.
+1  A: 

You declared instances as an array type:

String ^instances[] = (String^)rk->GetValue("InstalledInstances");

Instead, declare it as a string:

String ^instances = (String^)rk->GetValue("InstalledInstances");
Assaf Lavie