小编Gno*_*ght的帖子

C#Linq选择方法链中的问题

注意_src继承IQueryable<U>和V继承new();

我写了以下语句,没有语法错误.

IQueryable<V> a = from s in _src where (s.Right - 1 == s.Left) select new V();
Run Code Online (Sandbox Code Playgroud)

但如果我按如下方式重写它,Visual Studio编辑器会在"选择"中抱怨错误

IQueryable<V> d = _src.Where(s => s.Right - 1 == s.Left).Select(s=> new V());
Run Code Online (Sandbox Code Playgroud)

错误是:

The type arguments cannot be inferred from the usage. Try specifying the type arguments explicitly.
Candidates are:
  System.Collections.Generic.IEnumerable<V> Select<U,V>(this System.Collections.Generic.IEnumerable<U>, System.Func<U,V>) (in class Enumerable)
  System.Linq.IQueryable<V> Select<U,V>(this System.Linq.IQueryable<U>, System.Linq.Expressions.Expression<System.Func<U,V>>) (in class Queryable)
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释这种现象,解决错误的方法是什么?

===编辑(2010-03-16 5:35 pm)===

谢谢Mike Two.我也尝试了一个像你这样的简单例子.它可以工作,但这不是我的.我发布的代码如下:

public class NSM<U, V> where U …
Run Code Online (Sandbox Code Playgroud)

c# linq select selector

5
推荐指数
1
解决办法
3265
查看次数

Systemd ExecStart 中的 Bash Brace 扩展

以下测试是在 CentOS 7.1 中进行的。

创建以下文件test.service/usr/lib/systemd/system/

[Unit]
Description=Test Bash Brace Expansion
Wants=network.target
After=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/bash -c "a='hello world'; echo ${a}"

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

并执行 systemctl daemon-reload; systemctl restart test; systemctl status test -l

没有值的输出,因为${a}不作为词替代hello world,直到它echo ${a}变成

  1. echo $a : 工作
  2. echo $${a}: 工作

$$意味着 aa bash 中进程的 pid,但是为什么可以通过$$这个技巧ExecStart来获得这个词hello world呢?

linux bash centos brace-expansion systemd

4
推荐指数
1
解决办法
2451
查看次数

标签 统计

bash ×1

brace-expansion ×1

c# ×1

centos ×1

linq ×1

linux ×1

select ×1

selector ×1

systemd ×1