Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I cannot derive from long?

My function returns some long value which contains two values in lower and higher 32 bits.

I thought the best ways to handle return value is to derive my custom type from long and provide type extenders like GetLowerValue(), GetHigherValue().

The problem is that .NET does not allow to derive from long

If you compile that

public class SubmitOrderResult : long
{
}

you get:

cannot derive from sealed type 'long'

Why is that designed so and how can overcome it?

Thanks

like image 319
Captain Comic Avatar asked Nov 23 '09 12:11

Captain Comic


1 Answers

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.

Example

public static class LongExtensions
{
    public static long GetLowerValue(this long value)
    {
        ...
    }

    public static long GetHigherValue(this long value)
    {
        ...
    }
}
like image 199
James Avatar answered Oct 05 '22 04:10

James