我的函数会返回一些长期价值 其中载有低和高32位的两个值
My function returns some long value which contains two values in lower and higher 32 bits.
我还以为来处理返回值的最佳方式 是从长期得到我的自定义类型,并提供 型增量喜欢GetLowerValue(),GetHigherValue()。
I thought the best ways to handle return value is to derive my custom type from long and provide type extenders like GetLowerValue(), GetHigherValue().
的问题是,.NET不允许从长导出
The problem is that .NET does not allow to derive from long
如果您编译
public class SubmitOrderResult : long { }
您可以:
cannot derive from sealed type 'long'
这是为什么这样设计?如何克服呢?
Why is that designed so and how can overcome it?
感谢
推荐答案由于.NET中已经提到的值类型是密封的,所以没有办法,你可以从长派生。作为建议,您应该创建扩展方法。
As already mentioned value types in .NET are sealed so there is no way you can derive from long. You should create extension methods as suggested.
示例
public static class LongExtensions { public static long GetLowerValue(this long value) { ... } public static long GetHigherValue(this long value) { ... } }更多推荐
为什么我不能从长期获得?
发布评论