简体   繁体   English

永远不会分配给,并且将始终具有其默认值 0

[英]is never assigned to, and will always have its default value 0

I keep getting the above warning for both ordersubmitted and lastfillquantity , however everything seems to be working fine and when i print the the variables they seem to updating correctly.我一直收到ordersubmittedlastfillquantity的上述警告,但是一切似乎都运行良好,当我打印变量时,它们似乎正确更新。

public partial class Form1 : Form
{
    private bool ordersubmitted = false;
    private int lastfillquantity;

    private void SubmitOrder()
    {
        int lastfillquantity = e.filled;
        ordersubmitted = true
    }
}

You are not setting the value of the class property, instead you are creating a new property inside the method and assign the new value to that one.您不是在设置类属性的值,而是在方法内部创建一个新属性并将新值分配给该属性。 Try this:尝试这个:

public partial class Form1 : Form
{
    private bool ordersubmitted = false;
    private int lastfillquantity;

    private void SubmitOrder()
    {
        // here you need to assign it, instead of defining another class property
        lastfillquantity = e.filled;
        ordersubmitted = true
    }
}

It is not working fine.它不能正常工作。 As it says, you are never setting a value for it.正如它所说,你永远不会为它设置一个值。 You just define another variable with the same name in the method and set its value, just to throw it away.您只需在方法中定义另一个具有相同名称的变量并设置其值,就可以将其丢弃。 The class field never gets any other value than zero.类字段永远不会获得除零以外的任何其他值。

value of lastfillquantity variable is never updated, since you redeclare lastfillquantity inside SubmitOrder method and update new variable's (which hides outer one) value. lastfillquantity变量的值永远不会更新,因为您在SubmitOrder方法中重新声明lastfillquantity并更新新变量(隐藏外部变量)的值。 Instead you should update outer variable.相反,您应该更新外部变量。

Try following尝试以下

private void SubmitOrder()
{
    lastfillquantity = e.filled;
    ordersubmitted = true
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从未分配给它,并且将始终具有其默认值 - is never assigned to, and will always have its default value 字段从未分配给它,并且将始终具有其默认值 - Field is never assigned to, and will always have its default value 字段“ FIELD”从未分配,并且将始终具有其默认值 - field 'FIELD' is never assigned to, and will always have its default value 警告:永远不会将字段分配给,并且始终将其默认值设置为null - Warning: Field is never assigned to, and will always have its default value null 构造函数混淆 - '从未分配给,并且将始终具有其默认值' - Constructor Confusion - 'never assigned to, and will always have its default value' 字段modifyDate永远不会分配给,并且始终具有其默认值0 - Field modifyDate is never assigned to, and will always have its default value 0 构造函数DI - Field永远不会分配给,并且始终具有其默认值 - Constructor DI - Field is never assigned to, and will always have its default value 字段永远不会分配给,并且始终具有默认值0 - Field is never assigned to and will always have its default value 0 字段'xxx'永远不会分配给,并且将始终具有其默认值null - Field 'xxx' is never assigned to, and will always have its default value null 永远不会将字段xxx分配给,并始终将其默认值设置为null - Field xxx is never assigned to, and will always have its default value null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM