Unity 3D Game Dev Day 5: Why use _ in variable?

class ExampleClass
{
  int count;

  public void UpdateOurCount(int count)
  {
    this.count = count;
  }

}

this.count will be refer to the class field. count will be the method parameter.

So it is confusing.

It is better this way :

class ExampleClass
{
  int _count;

  public void UpdateOurCount(int count)
  {
    _count = count;
  }

}

_count will be a field, count will be local variable.Without the help of this.

Get New Tutorials by Email

No spam. Just clear, practical breakdowns you can apply right away.

Enjoy this tutorial?

Get new practical tech tutorials in your inbox.