You can do this by enabling implicit conversion from SampleClass to int:
public static implicit operator int(SampleClass s) { return s.value; }
... but I would strongly recommend that you not do this, or at least that you think very carefully in advance. Implicit conversions make it difficult to reason about a language in various ways (for example, consider things like, for example, resolving overloads).
Very, very sometimes it is recommended to introduce implicit conversions - for example, LINQ to XML makes excellent use of it with a string in XNamespace and a string in XName conversions, but I would not do this here just to avoid using .Value .
Itβs a little more reasonable to make an explicit conversion (just change the implicit to explicit in the conversion of the statement) so that at least it makes it clear what happens in the calling code ... but at the same time, in reality, there is a difference between the original size between cast to int and using .Value is small.
(And, as suggested elsewhere, do not make the fields public - use properties instead.)
Jon skeet
source share