Use of unassigned out parameter, c#

后端 未结 4 614
借酒劲吻你
借酒劲吻你 2020-12-29 01:06

I have very simple problem. I made a very simple function for you to demonstrate my problem.

static void Main(string[] args)       
{
    double[,] mydouble          


        
4条回答
  •  别那么骄傲
    2020-12-29 01:43

    The error message is clear - you need to assign a value to your out parameter inside your method:

    public static void mynewMatrix(out double[,] d)
    {
        d = new double[1, 4];
        for (int i = 0; i < 4; i++)
        {
            d[0,i]=i;
        }
    }
    

    The assignment you made outside the method has no effect. Just write this:

    static void Main(string[] args)       
    {
        double[,] mydouble;
        mynewMatrix(out mydouble);
    }
    

提交回复
热议问题