-4

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.

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

    private void SubmitOrder()
    {
        int lastfillquantity = e.filled;
        ordersubmitted = true
    }
}
user4891693
  • 35
  • 1
  • 2
  • 5
  • 1
    Possible duplicate of [Field xxx is never assigned to, and will always have its default value null](http://stackoverflow.com/questions/4811155/field-xxx-is-never-assigned-to-and-will-always-have-its-default-value-null) – CompuChip Mar 18 '16 at 16:34

3 Answers3

3

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
    }
}
Swag
  • 2,090
  • 9
  • 33
  • 63
2

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.

Sami Kuhmonen
  • 30,146
  • 9
  • 61
  • 74
1

value of lastfillquantity variable is never updated, since you redeclare lastfillquantity inside SubmitOrder method and update new variable's (which hides outer one) value. Instead you should update outer variable.

Try following

private void SubmitOrder()
{
    lastfillquantity = e.filled;
    ordersubmitted = true
}
tchelidze
  • 8,050
  • 1
  • 29
  • 49