因为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会抛出两个错误:
ulong result = (ulong)listOfA.Sum(A => (long)A.Id)
无论如何没有铸造解决这个问题?谢谢!
假设我在 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 的属性不兼容。