首页 > 学院 > 开发设计 > 正文

C#语法糖之开篇

2019-11-17 03:02:34
字体:
来源:转载
供稿:网友

C#语法糖之开篇

    本人虽然大学不是学的计算机但是对于IT行业的热爱,依然决然进军IT行业了,自从踏进这个行业到现在也已经3年多了,从去年开发通过网上 了解博客园后深深的爱上这儿了,这里有很多牛人,通过拜读他们的代码,让我突飞猛进,慢慢觉得脑子里有点东西了,平时学的东西也很多,很杂,所以有时学完 不用一段时间后很容易就忘了,所以心里就萌生了也想写文章,一来可以对知识的总结,二来可以过段时间后反过头来看,但是因为工作的原因一直没有开始,也有 自己懒惰的原因,今天坚决的决定开始记录我的学习中的每个点点滴滴,也对于刚开始入门的兄弟们一个参考的东西吧,因本人也是一个菜鸟,所以要是大神们看到 就多多见谅,多多担待吧!

    废话不多说了,刚开始就从C#的语法开始吧,但也讲最基础也估计没用,所以今天就从C#4.0的语法糖开刀吧!

    概 念:语法糖也译为糖衣语法,是由英国计算机科学家彼得·约翰·兰达(Peter J. Landin)发明的一个术语,指计算机语言中添加的某种语法,这种语法对语言的功能并没有影响,但是更方便程序员使用。通常来说使用语法糖能够增加程序 的可读性,从而减少程序代码出错的机会。

    需要声明的是“语法糖”这个词绝非贬义词,它可以给我带来方便,是一种便捷的写法,编译器会帮我们做转换;而且可以提高开发编码的效率,在性能上也不会带来损失,所以对于开发人员来说都很喜欢,很有甜头的感觉。

    在 编译器发展早期,编译器科学家门一直在想方设法的优化编译器生成的代码,这个时候,编译器做的主要是对机器优化,因为那个时候机器的时间非常宝贵,机器运 算速度也不快,今天我们有了足够好的机器了(但并不是说我们可以不关注性能的编写程序),而且作为编写软件的人来说,比机器的时间宝贵得多,所以今天的编 译器也在向人优化了,从编程语言的发展之路来讲,今天的编程语言比昨天的语言更高级,也更人性化了,我们只要编写更少的代码,更符合人的思维的代码,而只 要关注我们值的关注的地方。体力活儿就交给编译器吧。

    今天第一天我就把我打算记录的C#4.0语法糖的总体结构用图表示一下:

ipCAIAAABVAotnAAAgAElEQVR4n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