The purpose of the Tag
property is for you to use it for any purpose you want. You can safely store anything in there you want.
It is customary to declare a class that is specifically intended for being stored in the Tag
property (like you did with your CustClass
). But if you need only one value in it, then there is nothing wrong with storing an int
in it directly.
Where did you read that boxing/unboxing is “unsafe”? That is absolutely not true. (Some people claim that it is inefficient, but even that is not true.) Furthermore, your code does not even contain an example of boxing at all. CustClass
is a reference type. Only value types are boxed when assigned to object
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…