惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
T
Threat Research - Cisco Blogs
S
SegmentFault 最新的问题
V2EX - 技术
V2EX - 技术
Hacker News: Ask HN
Hacker News: Ask HN
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
P
Proofpoint News Feed
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
C
Cybersecurity and Infrastructure Security Agency CISA
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
U
Unit 42
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
H
Help Net Security
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 热门话题
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
H
Heimdal Security Blog
博客园 - 聂微东
S
Securelist
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
Cisco Talos Blog
Cisco Talos Blog

博客园 - 阿布

手Q兴趣号的价值在哪里 生命中绽放的花儿 Google发布App Engine 欲打造网络应用统一平台 NetBeans 7.0 揭密:用JavaScript重写,变成一个实足的在线IDE???!!! Rails存储库从SVN转向Git IKVM.NET,有点意思的Java虚拟机 Using Routing With WebForms 计划中的VS10特性将会作为VS2008的扩展而发布 使.NET运行在Linux, Mac OSX 和 FreeBSD(ouspec翻译) 使.NET运行在Linux, Mac OSX 和 FreeBSD(每个人都知道mono,但这里说的不是mono) 微软加入开源组织 微软发布 “Microsoft | NextWeb” 新展示站点 Google众高管跳槽至Facebook 基于Ubuntu的商业版 Linspire 6.0 发布! 教科书蒙蔽IT业很多年 世界第一台计算机名叫ABC Internet Explorer Administration Kit 7 RTM (IEAK)简体中文版 Vixta v0.94 - 基于Fedora Linux的Vista克隆版 微软到底为何取消IE7的正版验证 长江大学父子联手开发自由省略输入法
if ... else if ... else if ... else ... : an alternative
阿布 · 2008-03-11 · via 博客园 - 阿布

Like many tips & tricks concerning programming languages, what I will present here will be so utterly obvious to some C# developers, but could be an eye-opener to others.

How often do you write something like this?

        if (token == "A")
tokenNumber = 1;
else if (token == "B")
tokenNumber = 4;
else if (token == "C")
tokenNumber = 5;
else if (token == "X")
tokenNumber = 10;
else
tokenNumber = 20;


How about writing it like this?

      tokenNumber = (token == "A") ? 1:
(token == "B") ? 4:
(token == "C") ? 5:
(token == "X") ? 10:
20;

It's the same thing, but it looks cleaner, and the generated IL code is almost the same (it's even a bit shorter).

http://www.blog.activa.be/2008/03/11/ifElseIfElseIfElseAnAlternative.aspx