小编Z.Z*_*.Z.的帖子

c#Enumerable.Sum方法不支持ulong类型

因为c#Enumerable.Sum<TSource> Method (IEnumerable<TSource>, Func<TSource, Int64>)不支持ulong类型作为Mehtonf的返回类型,除非我将ulong转换为long.

public class A
{
  public ulong id {get;set;}

} 




publec Class B
{
    public void SomeMethod(IList<A> listOfA)
    {
        ulong result = listofA.Sum(A => A.Id);
    }
}
Run Code Online (Sandbox Code Playgroud)

compliler会抛出两个错误:

  1. 在此输入图像描述
  2. 在此输入图像描述

    除非我这样做

ulong result = (ulong)listOfA.Sum(A => (long)A.Id)

无论如何没有铸造解决这个问题?谢谢!

c# linq lambda

8
推荐指数
2
解决办法
2003
查看次数

Typescript 可以有与 Json 不区分大小写的属性匹配吗?

假设我在 Typescript 中有这个定义的类:

class Data{
   Dimension1: string;
   Dimension2: string;
   Metrics: Array<string>;
}
Run Code Online (Sandbox Code Playgroud)

有没有办法可以Data在下面声明一个带有 json 数据的实例(小写的属性)?

let json: Data = {
   "dimension1": "some dim",
   "dimension2": "some other dimes",
   "metrics": ["metric1", "metric2"]
}
Run Code Online (Sandbox Code Playgroud)

目前,编译器会抱怨 Type 的属性不兼容。

json typescript

7
推荐指数
1
解决办法
2865
查看次数

标签 统计

c# ×1

json ×1

lambda ×1

linq ×1

typescript ×1