您可以做的是编写一个带有隐式转换运算符的结构。这将完全按照您想要的方式工作:
public struct SubmitOrderResult
{
private long _result;
public SubmitOrderResult(long result)
{
_result = result;
}
public long Result
{
get { return _result; }
set { _result = value; }
}
public int GetHigherValue()
{
return (int)(_result >> 32);
}
public int GetLowerValue()
{
return (int)_result;
}
public static implicit operator SubmitOrderResult(long result)
{
return new SubmitOrderResult(result);
}
public static implicit operator long(SubmitOrderResult result)
{
return result._result;
}
}
然后你可以这样做:
SubmitOrderResult result = someObject.TheMethod();
Console.WriteLine(result.GetHigherValue());
Console.WriteLine(result.GetLowerValue());
......就像你想要的那样。