Code shows how to use implicit and explicit conversion. Especially it shows how to assign a int value straight to custom object, and how to retrieve int value from custom object by casting.

class Program
{
    static void Main(string[] args)
    {
        ImplicitType implicitType = 12345;
        Console.WriteLine(implicitType.Value);

        ExplicitType explicitType = new ExplicitType { Value = 67890 };
        int explicitTypeValue = (int)explicitType;
        Console.WriteLine(explicitTypeValue);
    }
}

class ImplicitType
{
    public int Value { get; set; }

    public static implicit operator ImplicitType(int value)
    {
        return new ImplicitType {Value = value};
    }
}

class ExplicitType
{
    public int Value { get; set; }

    public static explicit operator int(ExplicitType explicitType)
    {
        return explicitType.Value;
    }
}

 

12345
67890