LINQ Min and Max

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • qglyirnyfgfo@mailinator.com

    #1

    LINQ Min and Max

    I noticed that LINQ Min and Max methods have concrete implementations
    for some of the primitive data types but not for all. For example,
    LINQ has a Max concrete implementation for int collections defined as:

    public static int Max(this IEnumerable<int source)

    Other concrete implementations avalable are, Decimal, Decimal?,
    Double, Double? Etc.

    My question is, why does LINQ not have concrete implementation for
    *all* primitive types? For example, if you have a uint collection you
    will need to use the generic Max method and this method will not be as
    efficient as if there was a concrete implementation for unit
    collections such as:

    public static int Max(this IEnumerable< uint source)

    I realize that some of the privative types that were left out are not
    used as much as the ones that were implemented but come on, how long
    would have taken a Microsoft employee to implement this methods? It’s
    basically copy and paste from the other methods.

    Certainly, there must be other reasons for why they decided to go this
    way. Perhaps I will find such reason later as I learn more LINQ but
    for now, I was wondering if someone could shed some length to me.

    Thank you.
  • Jeroen Mostert

    #2
    Re: LINQ Min and Max

    qglyirnyfgfo@ma ilinator.com wrote:
    I noticed that LINQ Min and Max methods have concrete implementations
    for some of the primitive data types but not for all. For example,
    LINQ has a Max concrete implementation for int collections defined as:
    >
    public static int Max(this IEnumerable<int source)
    >
    Other concrete implementations avalable are, Decimal, Decimal?,
    Double, Double? Etc.
    >
    My question is, why does LINQ not have concrete implementation for
    *all* primitive types? For example, if you have a uint collection you
    will need to use the generic Max method and this method will not be as
    efficient as if there was a concrete implementation for unit
    collections such as:
    >
    public static int Max(this IEnumerable< uint source)
    >
    "uint" is not CLS-compliant. There are a rare few classes and methods in the
    framework library that operate on non-CLS compliant types, but those are
    special cases (like the ones taking pointers) and they have alternatives. It
    would make sense that LINQ doesn't bother with them.

    If you happen to have a collection of uints that you need to find the
    maximum of a lot *and* you really think you're getting a significant
    performance hit on the generic .Max() (which is doubtful to begin with)
    absolutely nothing is preventing you from writing your own extension method
    for it, which is rather trivial.
    I realize that some of the privative types that were left out are not
    used as much as the ones that were implemented but come on, how long
    would have taken a Microsoft employee to implement this methods? It’s
    basically copy and paste from the other methods.
    >
    Exactly, so go right ahead.

    --
    J.

    Comment

    Working...