Hi @Reza Jaferi , Welcome to Microsoft Q&A,
In C#, the terms 'private fields' and 'private instance fields' are usually equivalent, because in C# the field defaults to an instance field. Therefore, the term "instance" can be omitted here. In general, a private field is a field that can only be accessed in an instance (object) of a class.
And these two points do not seem to conflict, they can be held at the same time.
private int _myPrivateField;
private void MyMethod(int myArgument)
{
// Do something with myArgument and _myPrivateField
}
CamelCase for method arguments, local variables, and private fields: The code appears to follow this convention. For example, vehicleSpeed, turnSpeed, horizontalInput, and forwardInput all use camelCase.
You'll often find that in code examples, properties use "_" a lot:
private string _name = "John Doe";
public string Name
{
get { return _name; }
set { _name = value; }
}
Based on the provided code snippet, it seems to follow Microsoft's C# identifier naming conventions. The organization of regions (#region) is used, and the comments provide clarity on the purpose of fields and methods.
However, coding style can vary among developers and teams, so it's essential to be consistent with the conventions used in a specific codebase or project.
"Private instance fields are used when defining classes in object-oriented programming. They are not directly accessible outside the class and are meant for encapsulating data within the class. The names of private instance fields often begin with an underscore (_) to indicate their visibility scope and to signal to other developers that they should not be accessed directly from outside the class."
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.