此方法返回通用列表,但它有多个条件来获取选择.我只是写这个使用if - else if -else if ....如果这么多,我的意思是否有更短的方法来做到这一点?谢谢.
public List<ProductReqNoDate> GetRequestsQuery(string departmant, int reqStateID, string firstDate, string lastDate)
{
var db = new requestsDBEntities();
var listPrn = new List<ProductReqNoDate>();
if (!string.IsNullOrEmpty(departmant))
{
return (from r in db.requests
where r.departmant== departmant
select new ProductReqNoDate
{
departmant= r.departmant,
reqNo = r.reqNo ,
reqDate = r.reqDate ,
prdctName= stringCutter((from p in db.products where p.reqNo == r.reqNo select p.prdctName).FirstOrDefault())
}).ToList();
}
if (!string.IsNullOrEmpty(firstDate) && !string.IsNullOrEmpty(lastDate))
{
DateTime dtfirstDate = Convert.ToDateTime(firstDate);
DateTime dtlastDate = Convert.ToDateTime(lastDate);
return …Run Code Online (Sandbox Code Playgroud) 我已经尝试让这件事工作几个小时,但我无法让它工作:
if [ "$P" = "SFTP" -a "$PORT" != "22" ] || [ "$P" = "FTPS" && [ "$PORT" != "990" -a "$PORT" != "21" ] ] ; then
有人能帮我吗 ?我知道多个条件可以这样写:
if [ "$P" = "SFTP" ] && [ "$PORT" != "22" ]; then
但我怎样才能像第一个例子一样叠加这些条件呢?
bash if-statement nested multiple-conditions conditional-statements
我的Makefile是:
.PHONY: check
check:
ifneq $(shell echo 123), $(shell echo 123)
$(error Not equal)
endif
Run Code Online (Sandbox Code Playgroud)
当我运行时,出现错误:
$ make
Makefile:3: *** Not equal. Stop.
Run Code Online (Sandbox Code Playgroud)
但这应该只有当它们不同时才会发生,但事实并非如此。为什么?
我在 C# 项目中将条件编译符号定义为“ABC;XYZ”,并且我可以在项目 XML 文件中使用以下内容,以便在 MSBuild 期间有条件包含项目代码文件:
<Compile Include="SomeFile.cs" Condition="$(DefineConstants)'=='ABC;XYZ'"/>
Run Code Online (Sandbox Code Playgroud)
但我需要类似以下的东西,但它不起作用:
<Compile Include="SomeFile.cs" Condition="$(DefineConstants)'=='ABC'"/>
Run Code Online (Sandbox Code Playgroud)
是否可以仅使用其中一个定义常量进行条件测试?
我正在学习 Python,我试图了解 apply() 方法在 Pandas 数据帧中的工作原理。
作为练习,我想使用一行代码将 str.upper() 方法应用于 Pandas 数据框的元素,仅当这些元素是字符串时。
我想将 lambda 条件表达式与 apply 结合起来,但问题是当 apply 调用 Pandas 数据帧时,数据帧——如果我理解得很好——返回一个要应用的系列,然后将它传递给函数。我想知道如何更深入地调用 Pandas 数据框元素上的函数。
这就是我在对 DataFrame 的列(系列)调用 apply() 时按我的意图执行的操作:
df= pd.DataFrame([[1, 'a'],['b',2]], columns = ['A', 'B'] )
df['A'].apply(lambda x: str.upper(x) if type(x) is str else x)
Run Code Online (Sandbox Code Playgroud)
但是我怎么能用一行代码在整个数据帧上做到这一点呢?
我正在寻找一种解决方案,该解决方案可以处理包含数字和字符串的列,并且可以保持数字不变。
我有一个(这里非常简单)pandas 数据框,它看起来像这样:
df
datetime user type msg
0 2012-11-11 15:41:08 u1 txt hello world
1 2012-11-11 15:41:11 u2 txt hello world
2 2012-11-21 17:00:08 u3 txt hello world
3 2012-11-22 18:08:35 u4 txt hello you
4 2012-11-22 18:08:37 u5 txt hello you
Run Code Online (Sandbox Code Playgroud)
我现在想做的是在 3 秒内获取所有具有时间戳的重复消息。所需的输出是:
datetime user type msg
0 2012-11-11 15:41:08 u1 txt hello world
1 2012-11-11 15:41:11 u2 txt hello world
3 2012-11-22 18:08:35 u4 txt hello you
4 2012-11-22 18:08:37 u5 …Run Code Online (Sandbox Code Playgroud) 我想使用 ref,但是我无法在最初为 false 的条件渲染中使用它。
constructor(props) {
super(props);
this.state = {
filterActive: false,
}
this.firstRef = React.createRef();
}
Run Code Online (Sandbox Code Playgroud)
如果我在此使用 ref :-
{this.state.filterActive ?
<label ref={this.firstRef}>Time Range</label>
:null}
Run Code Online (Sandbox Code Playgroud)
引用为空。
我正在为 Java 考试而学习,遇到了“unreachable statement”编译器错误,例如:
Source.java:10: error: unreachable statement
System.out.println("This code is not reachable");
Run Code Online (Sandbox Code Playgroud)
我试图了解何时会或不会发生这种情况-例如,在这些情况下不会发生这种情况:
// Case #1
if (true) {
System.out.println("This code is reachable");
} else {
System.out.println("This code is not reachable"); // Compiles OK
}
// Case #2
for (i = 0; i < 5; i++) {
if (true) continue;
System.out.println("This code is not reachable"); // Compiles OK
}
Run Code Online (Sandbox Code Playgroud)
似乎编译器不够聪明,无法检测到if条件何时持续true- 有人可以提供更详细的解释吗?
java if-statement compiler-errors conditional-statements unreachable-statement
考虑向量:
use = c(1,1,2,2,5,1,2,1,2,5,1)
在第一个数字 5 出现在序列中之前,我试图将所有 5 不同的数字替换为 NA:
ifelse(use != 5,NA,1)。之后的条件应该是
ifelse(use != 5,0,1)。
输出将是:
after = c(NA,NA,NA,NA,1,0,0,0,0,1,0)
有小费吗?
我有一个遗传数据集,我希望在其中对样本/基因进行排序,并按基因组中彼此相距一定距离的样本/基因进行分组。
例如,我的数据集如下所示:
#dt1
Gene chromosome position CP
Gene1 1 70000200 1:70000200
Gene2 5 10000476 5:10000476
Gene3 1 70000201 1:70000201
Gene4 5 10000475 5:10000475
Run Code Online (Sandbox Code Playgroud)
我还有一个原点位置数据集:
#dt2
chromosome position CP
1 70005000 1:70005000
5 10005000 5:10005000
Run Code Online (Sandbox Code Playgroud)
如果基因在我的第二个 dt2 数据集中的任何位置的 +/- 500000 距离内并且在同一条染色体上,我正在尝试对我的第一个数据集中的基因进行分组。我的实际数据中存在一个问题,对于针对多个起源 dt2 位置的基因来说,这可能是正确的,所以我也试图对它最接近的一个进行排序。
输出旨在给出有序组:
Gene chromosome position Group
Gene1 1 70000200 1
Gene3 1 70000201 1
Gene4 5 10000475 2
Gene2 5 10000476 2
Run Code Online (Sandbox Code Playgroud)
Gene1 和 Gene3 位于原始 dt2 位置的 500000 范围内,并且都在同一条染色体上,因此分组在一起,并且基因 4 和 2 相同
目前我正在尝试这样做:
dt2[, c("low", "high") := …Run Code Online (Sandbox Code Playgroud) if-statement ×4
pandas ×2
python ×2
r ×2
apply ×1
bash ×1
compilation ×1
data.table ×1
datetime ×1
duplicates ×1
include ×1
java ×1
javascript ×1
lambda ×1
linq ×1
makefile ×1
msbuild ×1
nested ×1
reactjs ×1
ref ×1
render ×1
replace ×1
shell ×1
vector ×1
where ×1