Does anyone know of any naming convention rules/guidelines that dictate when to use a "To" prefix (myVariable.ToList()
), an "As" prefix (myVariable.AsEnumerable()
), or a "Get" prefix (myVariable.GetHashCode()
)?
I assume there's no convention, so just use what fits best to what you're doing.
iterators
My understanding/conventions:
"To" performs a conversion; A new object is created in memory, based on the data inherent in your source.
"As" performs a cast; The same reference passed in is returned behind the "mask" of a different type.
"Get" performs pretty much anything else that takes in a source and whose primary product is a transformed result. Gets can perform a calculation, return a child, retrieve data from a store, instantiate objects from a default state, etc. Not all such methods have to be named "Get", but most methods intended to calculate, instantiate, project, or otherwise transform, and then return the product as their primary purpose are "getters".
myObj
is not related to List
, prefix "To" to convert.myObj
is a subclass of Enumerable
, prefix "As" to give it as EnumerablemyObj
is not related to List
, but it composes / can compose List
use "Get" prefixIf 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