How Does ‘this’ work?

I've been programming for a year, and have no idea how 'this' works.

Here's an example that uses it: using UnityEngine; using System.Collections;

 public class Ctrl : MonoBehaviour { void Update () { if (Input.GetKeyDown(KeyCode.LeftArrow)) { Vector3 position = this.transform.position; position.x--; this.transform.position = position; } if (Input.GetKeyDown(KeyCode.RightArrow)) { Vector3 position = this.transform.position; position.x++; this.transform.position = position; } if (Input.GetKeyDown(KeyCode.UpArrow)) { Vector3 position = this.transform.position; position.y++; this.transform.position = position; } if (Input.GetKeyDown(KeyCode.DownArrow)) { Vector3 position = this.transform.position; position.y--; this.transform.position = position; } } } 

Although this is in Unity, I'd also like to know how it works in newer version of .NET

by Ovicior via /r/csharp

Leave a Reply