如何将结构/数组从类函数返回到我的主函数?

时间:2015-08-05 21:05:12

标签: c# arrays class structure

我希望有人可以帮助我!

我只想将一个结构/数组从我的类函数返回到我的主程序函数。

但我总是收到错误:

CS0029 C# Cannot implicitly convert type 'MyClass.MyStructerInClass[]' to 'MyMainProgramm.MyStructerInMainProgramm[]

代码很简单,希望能够自我解释:

class MyClass
{
    public struct MyStructerInClass
    {
        public string string1;
        public string string2;
        public int int1;
        public int int2;
        public int int3;
        public double double1;
        public double double2;
        public DateTime time1;
    }

    public MyStructerInClass[] NewStructerInClass = new MyStructerInClass[100];

    public MyClass()
    {

    }

    public MyStructerInClass[] MyFunctionInClass()
    {
        //do some stuff

        return NewStructerInClass
    }       
}

namespace MyMainProgramm
{
    public struct MyStructerInMainProgramm
    {
        public string string1;
        public string string2;
        public int int1;
        public int int2;
        public int int3;
        public double double1;
        public double double2;
        public DateTime time1;
    }

    public MyStructer[] NewStructerInMainProgramm = new MyStructer[100];

    private void MainFunction()
    {
        NewStructerInMainProgramm = MyClass.MyFunctionInClass();
        //Here Error: CS0029 C# Cannot implicitly convert type 'MyClass.MyStructerInClass[]' to 'MyMainProgramm.MyStructerInMainProgramm[]'                       
    }
}

0 个答案:

没有答案