C#使用未分配的局部变量 - 输出语句

Mat*_*291 3 c# out

我已经找到了这个问题,但我不知道(并没有找到)如何解决它.这里有谁知道如何解决这个问题?我正在使用EMGU,但问题在于c#编码(我对C#来说相当新) - 我认为这与out语句有关,因为我没有太多使用它们:

Image<Gray, Byte> first_image;

if (start_at_frame_1 == true)
{
    Perform_custom_routine(imput_frame, out first_image);
}
else
{
     Perform_custom_routine(imput_frame, out second_image);
}

Comparison(first_image);
Run Code Online (Sandbox Code Playgroud)

Sha*_*ard 8

您必须为变量赋予默认值:

Image<Gray, Byte> first_image = null;
Run Code Online (Sandbox Code Playgroud)

否则,如果您second_image作为out参数传递,则有可能不会分配任何内容.