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

推荐订阅源

N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
Hugging Face - Blog
Hugging Face - Blog
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
D
Docker
C
Cyber Attacks, Cyber Crime and Cyber Security
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
T
Tenable Blog
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
The Hacker News
The Hacker News
Project Zero
Project Zero
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Scott Helme
Scott Helme
A
About on SuperTechFans
WordPress大学
WordPress大学
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
G
GRAHAM CLULEY
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Schneier on Security

博客园 - 阿布

手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