公共类 EncryptVal { private EncryptVal(T value) { Set( value ); }
// Encrypt
public bool Set(T value)
{}
// Decrypt & return (T)value;
public T Get()
{}
public static implicit operator EncryptVal<T>(T value) {
//shuffle bits
return new EncryptVal<T>(value);
}
public static implicit operator T(EncryptVal<T> value) {
//unshuffle bits
return value.Get(); ///// error ...
}
}
我无法重载 + 运算符和 ++ 运算符。我怎样才能做到这一点?
用法:
EncryptVal<int> e = 42;
EncryptVal<int> f = 1;
Console.WriteLine("decrypt int count \t= {0:d}", f.Get()); // ok
Console.WriteLine("decrypt int count \t= {0:d}", f); // error
Console.WriteLine("decrypt int count \t= {0:d}", e); //how?