为什么我不能从长期获得?

编程入门 行业动态 更新时间:2024-10-27 08:26:13
本文介绍了为什么我不能从长期获得?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的函数会返回一些长期价值 其中载有低和高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) { ... } }

更多推荐

为什么我不能从长期获得?

本文发布于:2023-11-15 19:52:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1597466.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!