在C#三元运算符中调用函数

时间:2016-07-19 06:24:52

标签: c# ternary-operator

为什么这段代码无效?很确定它在C / C ++中是合法的

伪代码:

X509Certificate2 certificate = GetStoreCertificate("<thumbprint>");
var clientHandler = new WebRequestHandler()
clientHandler.ClientCertificates.Add(certificate);
var client = new HttpClient(clientHandler)

3 个答案:

答案 0 :(得分:1)

console.writeline return void ..条件运算符(?:)根据布尔表达式的值返回两个值之一

MSDN

答案 1 :(得分:1)

三元运算符用于返回值,必须分配这些值。

如果要在三元运算符中调用void方法,可以使用如下代理:

Gestartet durch Benutzer Kevin Hissel
Baue in Arbeitsbereich /var/lib/jenkins/jobs/HelloWorld/workspace
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/kevinswen    /HelloWorld.git # timeout=10
Fetching upstream changes from https://github.com/kevinswen/HelloWorld.git
 > git --version # timeout=10
 > git -c core.askpass=true fetch --tags --progress https://github.com    /kevinswen/HelloWorld.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 5cab38db0b79e9ecea4fa7f14a5f6762973fccbf  (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 5cab38db0b79e9ecea4fa7f14a5f6762973fccbf
 > git rev-list 5cab38db0b79e9ecea4fa7f14a5f6762973fccbf # timeout=10
[HelloWorld] $ ant -file build.xml
Buildfile: /home/kevin/workspace/HelloWorld/build.xml

build-subprojects:

init:

build-project:
     [echo] HelloWorld: /home/kevin/workspace/HelloWorld/build.xml

compile:

BUILD SUCCESSFUL
Total time: 0 seconds
Zeichne Testergebnisse auf.
ERROR: Step ‘Veröffentliche JUnit-Testergebnisse.’ failed: Keine JUnit-     Testergebnisse gefunden. Liegt vielleicht ein Konfigurationsfehler vor?
Finished: FAILURE

答案 2 :(得分:0)

正如here所讨论的那样,在C#中,并非每个表达式都可以用作语句。