I'm trying to look at the C# Coding Standards to make my code more beautiful and standard, and I have a question: Does functions (methods that are not voids), according to the C# coding standards, should start with "Get"? For example: "GetSongOrder()
", "GetNextLine()
" etc?
Thanks.
There are two cases:
If the routine can "get" the value very quickly, without causing side effects in the code, I recommend using a property getter, and omitting the "get" name:
public SongOrder SongOrder
{
get { return this.songOrder; } // ie: an enum
}
If, however, there is processing required, then a method with the "Get..." name is appropriate. This suggests that there may be side effects to calling this method, such as extra processing, or a change in some state:
public string GetNextLine()
{
string line = this.stream.ReadLine(); // This may cause a longer running operation, especially if it's using Disk IO/etc
// do other work?
return line;
}
Your function name should be succinct, and make sense. Nothing more, nothing less.
If get works for you, then use Get. If Retrieve works, use that.
There is no true "standard" for naming conventions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With