4

I have an interesting question regarding C# code. Basically I have to call a method

BCI2000AutomationLib.IBCI2000Remote.StartupModules(ref System.Array)

Using Visual Studio 2010 the following code compiles and works perfectly:

// Startup modules
string[] modules = new string[3];
modules[0] = "SignalGenerator --local";
modules[1] = "DummySignalProcessing --local";
modules[2] = "DummyApplication --local";
ok_conn = bci.StartupModules(ref modules);

Now porting this to a game engine (e.g. Unity 3D) requires some stricter C# code since it uses Mono C# compiler. So for the same code i get the following compilation error:

The best overloaded method match for 'BCI2000AutomationLib.IBCI2000Remote.StartupModules(ref System.Array)' has some invalid arguments Argument 1: cannot convert from 'ref string[]' to 'ref System.Array'

Can you please give an advice on how to rewrite this code block to a more strict coding to resolve the stated error?

1
  • I can't get the above to compile - you're missing a parameter name on the declaration, and even with that fixed, I get what I expected - an error "cannot convert from 'ref string[]' to 'ref System.Array'". Can you produce a short and complete example that compiles in VS? Commented Jul 9, 2012 at 7:14

2 Answers 2

4

Change the type of you variable to System.Array

// Startup modules 
Array modules = new string[3] 
{
    "SignalGenerator --local",
    "DummySignalProcessing --local",
    "DummyApplication --local"
};
ok_conn = bci.StartupModules(ref modules); 

Your method StartupModules takes a ref Array as argument ; it can set the variable to any other Array. Not necessarily a string Array, it could be an int[]. That's why you cannot call with a variable typed as Array of string.

Sign up to request clarification or add additional context in comments.

2 Comments

This is perfect. Thanks for the explanation. I was able to compile and run in the Mono C# compiler without problem. Unfortunately Unity3D outputs the error: ArgumentException: Value does not fall within the expected range. System.Runtime.InteropServices.Marshal.ThrowExceptionForHR (Int32 errorCode) (wrapper cominterop) BCI2000AutomationLib.BCI2000RemoteClass:StartupModules (System.Array&) (wrapper cominterop-invoke) BCI2000AutomationLib.BCI2000RemoteClass:StartupModules (System.Array&) But I guess I have to ask the Unity and BCI2000 developers on this error.
Glad to help you, ask them or post a new question here.
-1

String Array program, taking string from user:

class Program
{
    static void Main(string[] args)
    {
        int i,j;
        string[] str = new string[10];
        Console.WriteLine("Enter the Name of your friends");
        for (i = 0; i < 10; i++)
        {
            str[i] = Convert.ToString(Console.ReadLine());
            Console.WriteLine("Array["+i+"]="+str[i]);
        }
        Console.ReadLine();
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.