I have a simple scenario that may or may not be possible. I have a class that contains an integer, for this purpose I\'ll make it as simple as possible:
pub
Implicit type conversion: Implicit type conversion takes place between smaller to larger integral types but not vice-versa or between derived class and base class. Conversion takes place in type safe manner by C# and no data loss takes place. For example,
int a = 10;
long b = a;
float f = a;
Explicit type conversion: Explicit type conversion done by using built-in C# functions. Data may be lost while explicit type conversion, means if we convert double to int then precision may be lost. Explicit type conversion require casting. To do a casting, need to specify the type that you are casting to in front of the value or variable to be converted.
For example,
double d = 10.20;
int a = (int)d;
//Output: 10
To understand in details follow C# Basics - C# Type Conversion
Implicit conversion
// Implicit conversion. num long can
// hold any value an int can hold, and more!
int num = 2147483647;
long bigNum = num;
Explicit Conversion
class Test
{
static void Main()
{
double x = 1234.7;
int a;
// Cast double to int.
a = (int)x;
System.Console.WriteLine(a);
}
}
Hope this may help you.
Try something like this
public static implicit operator int(Number num)
{
return num.Value;
}
class Number
{
public static implicit operator int(Number n)
{
return n.Value;
}
}