.NET Structs to which you can assign constant values ​​directly as built-in types

Can you create a structure that behaves like one of the built-in classes where you can directly assign a value without calling a property?

Example:

RoundedDouble count; count = 5; 

Instead of using

 RoundedDouble count; count.Value = 5; 
+4
source share
1 answer

You do this with an implicit keyword.

For example, in your case, you need something like:

 public static implicit operator RoundedDouble(double value) { return new RoundedDouble(value); } 
+10
source

All Articles