-1
公共類EncryptVal { 私人EncryptVal(T值) { 集(值); }運算符重載在C# 「+」 和 「+ +」
// 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?
您顯示的代碼與問題沒有多大關係。我既沒有看到+運算符的重載,也沒有看到它的用法。 –
我怎麼做這個+運算符&++操作符。 T是int,float,double。和你會得到價值只有變量沒有使用()得到? – user2725053