set and get keywords

string Name {get; set;}

what does the get and set keywords to the Name Variable?

In this case Name is not a variable but a property with implicit getter and setter.
A property handles the way a variable can be accessed by other scripts.

To better understand what a property does you could look at this example

private string _name;
public string Name {
  get {
    return _name;
  }
  set {
    _name = value;
  }
}

Now that seems like a whole lot of useless, but it gives potential to do stuff to the value before setting it to the name variable, or before returning it to the caller. Or you could restrict the access another script has to the variable (by not creating the set {} or by making set {} private)

For example, we could do fun things like making sure the first character in name is always uppercase

private string _name;
public string Name {
  get {
    return _name;
  }
  set {
    _name = char.ToUpper(value[0]) + value.Substring(1); // make first letter uppercase
  }
}

further reading: Properties - C# | Microsoft Learn

5 Likes