In Blazor when I have a private field / property in the code that will be used in the diplay / razor page, should it have a naming convention of camelcase (e.g. someVariable) or should I have an underscore with camel case (e.g. _anotherVariable).
E.g. in code
private string someVariable {get; set;}
private string _anotherVariable {get; set;}
in razor
I've found documentation for both styles - just looking for what's considered 'best' in the community of Blazor.
Other questions I have - should the variables be marked 'private' or 'protected' and do they need to be properties with the {get; set;} or should I only do this for public properties??
Thanks in advance for helping me straighten this out.
The style of the naming convention is up to your preference. There isn't a style guide for Blazor.
Look at
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions
Refer to the style guide for ASP.NET in case you want to follow the best practice from Microsoft.
Private is a good choice for variables visibility in case you work on the same page with @code.
Protected is more useful in case of derived classes.
The variables doesn't need to be declared as properties with getter and setter.
You HAVE to use getter and setter for parameters, cascading parameters and injected classes in code behind.