English 中文(简体)
因此,我无法通过一个直径的未签名物体变数,然后分配。
原标题:why can t I pass an unassigned object variable in an out parameter and then assign it

在C#中,为什么我通过一个<代码>>out 参数的未签署物体变数,然后加以分配?

如果我尝试这样做的话,就会出现一个汇编错误: 当地变量<xyz>不能在此范围内宣布,因为它将给<代码><xyz>. >。

例如。

void MyMethod(int x, out MyObject mo) {  **MyObject** mo = new MyObject(); }
// in some other scope:
MyObject mo;
MyMethod(1, out mo);

EDIT:我现在可以看到我的错误。 我已将上述法典改为地雷。 不应有星号上的

最佳回答

你颁布的法典是不正确的,但现在我们看到问题实际上在这里:

void MyMethod(int x, out MyObject mo)
{
    MyObject mo = new MyObject();
    // should be:
    // mo = new MyObject();
}

页: 1

Gla:

问题回答

这一错误信息意味着,同一方法中有些地方还有另一个称为<代码>mo的变量。 例如,这种法典会造成这一错误:

for( int mo = 0; i < 5; i++ ) Console.WriteLine( mo );

MyObject mo;

你也许不认为是相关的,因此你没有把整个法典放在后面。

鉴于你的实际代码,你无法界定 mo体,因为它已经定义为直线参数。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...