❔ The best way to create custom types?
Hey, what's the best way to implement a custom type?
E.g. I want an Id and instead of having it like this:
I want it like that:
So I don't calculate with the ID for example because it's an ID, not some random number.
11 Replies
Use a readonly struct or something and add an implicit conversion operator
something like this
If a method expects an ID and that implicit exists, will it accept an int in its place?
On phone so can't test
yeah
well, overload resolution will do its best to figure it out
Yeah, that's what I suspected. I'd recommend not having an implicit then
That's a good point.
Creating IDs from literals should be rare enough that a constructor or explicit isnt too much of a hurdle
Also, are all integers valid IDs?
So I guess something like this would be the best way still?
value
could just be a propertyTrue, at this point..
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.