-1

public class EncryptVal { private EncryptVal(T 値) { Set( 値 ); }

    // 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?
4

1 に答える 1

0

オーバーロードするには、+または必要な/演算子を++追加するだけです...+++

public static EncryptVal<T> operator ++(EncryptVal<T> value)
{
    throw new NotImplementedException(); // your implementation here
}
public static EncryptVal<T> operator +(EncryptVal<T> lhs, string rhs)
{
    throw new NotImplementedException(); // your implementation here
}
public static EncryptVal<T> operator +(EncryptVal<T> lhs, EncryptVal<T> rhs)
{
    throw new NotImplementedException(); // your implementation here
}
public static EncryptVal<T> operator +(EncryptVal<T> lhs, int rhs)
{
    throw new NotImplementedException(); // your implementation here
}
public static EncryptVal<T> operator +(bool lhs, EncryptVal<T> rhs)
{
    throw new NotImplementedException(); // your implementation here
}

ただし、これが残りの質問にどのように関連するかは不明です。特に、はおそらく何よりもConsole.WriteLine欲しがるでしょう。public override ToString()

于 2013-08-28T11:17:43.480 に答える