c# - Initialize object by assignment? -
how give types ability initialize via assignment, following:
public struct wrappedbyte { private byte m_value; } //usage: wrappedbyte x = 0xff;
you need use custom implicit operator. note doesn't apply structs.
public struct wrappedbyte { private byte m_value; public static implicit operator wrappedbyte(byte b) { return new wrappedbyte() { m_value = b }; } }
also note won't apply initialization; mean can supply byte
in location wrappedbyte
expected. includes assignments other initializations, parameters methods, etc.
Comments
Post a Comment