C
C#16mo ago
kanaizo

Naming convention question

So for context, for educational purposes (and only to learn), I'm trying to reconstruct the box packing system from my job. Now, I have a enum that contains all the different types of boxes, its called BoxType, and its inside of the Shipment (aka box) class. I want to have a BoxType property, and I feel like "BoxType" is also a good name for the property name, but as you could imagine, it says I'm not allowed to do this as the enum is already called "BoxType". And i thought "maybe lets put the b as lowercase", and now it gives me a warning that there's a naming convention issue, and that it should start with a B. Now I know this doesn't matter, but I'm trying to learn best practices for the future. What's the right way to do this? I might suck at explaining stuff, but here's what I mean.
class Shipment
{
// here below
BoxType BoxType = BoxType.Unknown

enum BoxType
{
Unknown
SizeOne,
SizeTwo
}
}
class Shipment
{
// here below
BoxType BoxType = BoxType.Unknown

enum BoxType
{
Unknown
SizeOne,
SizeTwo
}
}
9 Replies
kanaizo
kanaizoOP16mo ago
now that I'm thinking more clearly, maybe the BoxType enum should be BoxTypes?
mtreit
mtreit16mo ago
No Naming convention for enums is singular
mtreit
mtreit16mo ago
Names of Classes, Structs, and Interfaces - Framework Design Guidel...
Use these guidelines for naming Classes, Structs, and Interfaces as part of guidelines for designing libraries that extend and interact .NET libraries.
mtreit
mtreit16mo ago
I actually think your example is fine. What says it's not allowed? It should really be a property not a field but I think the name should be ok?
kanaizo
kanaizoOP16mo ago
The type "Shipment" already contains a definition for "BoxType"
mtreit
mtreit16mo ago
Oh. Move the enum declaration outside of the class definition I didn't notice it was nested
kanaizo
kanaizoOP16mo ago
Should enums not be nested in classes?
mtreit
mtreit16mo ago
Not usually, no
kanaizo
kanaizoOP16mo ago
okay, hehe im still new to this tbh. thank you for the help :)
Want results from more Discord servers?
Add your server