sách gpt4 ai đã đi

Không thể truy cập biểu thức từ 'System.Linq.Expressions.Expression<>>' được chuyển đổi thành 'System.Linq.Expressions.Expression<>>'

In lại 作者:行者123 更新时间:2023-12-04 10:52:53 31 4
mua khóa gpt4 Nike

为什么以下不编译?

using System;
using System.Linq;
using System.Linq.Expressions;

public static class Extensions
{
public static V? SumOrDefault(this IQueryable @this, Expression<>> selector)
where V : struct, IComparable, IComparable, IConvertible, IEquatable, IFormattable
{
Expression<>> nullableSelector = null; // omitted for brevity
return Queryable.Sum(@this, nullableSelector);
}
}

它给出了这个错误:
error CS1503: Argument 2: cannot convert from 'System.Linq.Expressions.Expression<>>' to 'System.Linq.Expressions.Expression<>>'

两个问题:
  • 为什么尝试调用 số thập phân 却失败了Sum<> 的版本?
  • 为什么找不到decimal? System.Linq.Queryable 中该函数的版本?
  •         public static decimal? Sum(this IQueryable source, Expression<>> selector);

    1 Câu trả lời

    如果这行得通,从技术上讲,你可以称之为 SumOrDefault具有十进制无法转换但仍尊重您的Ở đâu的功能(例如,sợi dây 一个自定义的“不可总结”类)。

    而且找不到decimal?函数的版本,因为它不知道要安全地转换为哪种类型。

    C# 没有办法将类型过滤为仅数字,AFAIK,因此您必须像 2001 一样手动重载它们:

    public static decimal? SumOrDefault(this IQueryable @this, Expression<>> selector)
    public static double? SumOrDefault(this IQueryable @this, Expression<>> selector)

    //etc.

    关于c# - 无法从 'System.Linq.Expressions.Expression<>>' 转换为 'System.Linq.Expressions.Expression<>>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59380420/

    31 4 0
    行者123
    Hồ sơ cá nhân

    Tôi là một lập trình viên xuất sắc, rất giỏi!

    Nhận phiếu giảm giá Didi Taxi miễn phí
    Mã giảm giá Didi Taxi
    Giấy chứng nhận ICP Bắc Kinh số 000000
    Hợp tác quảng cáo: 1813099741@qq.com 6ren.com