我在我的应用程序中使用了linq
var FinalSubExpired = subExpired.Where(e => (DateTime.Now - Convert.ToDateTime(e.AreasOfLawTillDate)).TotalDays <= 30 ).ToList();
Run Code Online (Sandbox Code Playgroud)
返回带有负值的总天数,我需要从总天数中删除该负号.我怎么能通过修改这个linq来做到这一点?
请帮忙.
为什么我使用下面的代码 IndexOutOfBoundsException
码:
List<Integer> ints = Stream.of(21,22,32,42,52).collect(Collectors.toList());
System.out.print("the list: ");
ints.forEach((i) -> {
System.out.print(ints.get(i-1) + " ");
});
Run Code Online (Sandbox Code Playgroud)
我的错误堆栈:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 11, Size: 5
at java.util.ArrayList.rangeCheck(ArrayList.java:638)
at java.util.ArrayList.get(ArrayList.java:414)
at Agent.lambda$main$1(Agent.java:33)
at Agent$$Lambda$8/980546781.accept(Unknown Source)
at java.util.ArrayList.forEach(ArrayList.java:1234)
at Agent.main(Agent.java:32)
the list: Java Result: 1
Run Code Online (Sandbox Code Playgroud)
但是当我将列表更改为一位数时,一切都很好
码:
List<Integer> ints = Stream.of(2,8,7,4,3).collect(Collectors.toList());
System.out.print("the list: ");
ints.forEach((i) -> {
System.out.print(ints.get(i-1) + " ");
});
Run Code Online (Sandbox Code Playgroud)
输出:
2 8 7 4 3
Run Code Online (Sandbox Code Playgroud) import java.util.function.Function;
public class LambdaExpression {
@SuppressWarnings("rawtypes")
public static Function create(int addTo){
int n = 1;
Function<Integer, Integer> f = addT -> addTo + n;
return f;
}
public static void main(String[] args){
System.out.println(LambdaExpression.create(5));
}
}
Run Code Online (Sandbox Code Playgroud)
在运行时给我这个错误:
LambdaExpression $$ LAMBDA $424058530分之1@ 1c20c684
如果我有这些数据:
a = [['a', 'b', 'b', 'v', 'd'],
['d', 'f', 'g'], ['q', 'w', 'e', 'r', 't', 'y'],
['x', '123', 'v', 'b'], ['g', 'h', 'i']]
Run Code Online (Sandbox Code Playgroud)
我想运行一个函数(最好是单行),它将返回列表列表中123具有最长字符串长度的函数.我怎样才能做到这一点?
我唯一看到的是在列表列表中找到最长的列表,所以这是一个稍微不同的问题.
我正在使用下面的python代码创建字典。但是我收到dct_structure变量的一个PEP 8警告。警告是:do not use a lambda expression use a def
from collections import defaultdict
dct_structure = lambda: defaultdict(dct_structure)
dct = dct_structure()
dct['protocol']['tcp'] = 'reliable'
dct['protocol']['udp'] = 'unreliable'
Run Code Online (Sandbox Code Playgroud)
我对python lambda表达式还不满意。因此,任何人都可以帮助我为以下两行python代码定义函数以避免PEP警告。
dct_structure = lambda: defaultdict(dct_structure)
dct = dct_structure()
Run Code Online (Sandbox Code Playgroud) 在此查询中:
var test = db.table.Where(x=>x.id == x).Where(x=>x.name == name).ToList();
Run Code Online (Sandbox Code Playgroud)
在SQL语言中使用AND或OR是一样的吗?
lambda ×7
c# ×3
java ×2
java-8 ×2
linq ×2
python ×2
asp.net-mvc ×1
defaultdict ×1
expression ×1
foreach ×1
python-3.x ×1