Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Tips and Tricks To Improve Code Readability in C#
Search
Jaime
June 10, 2012
Programming
5
910
Tips and Tricks To Improve Code Readability in C#
Jaime
June 10, 2012
Tweet
Share
More Decks by Jaime
See All by Jaime
Mastering the Arcane Art of JavaScriptmancy @ DevSum
vintharas
1
730
From Angular 1 to Angular 2
vintharas
0
2.1k
Mastering The Arcane Art of JavaScriptmancy - Swetugg Edition
vintharas
1
1.5k
Mastering the Arcane Art of JavaScript-mancy
vintharas
0
3.8k
Level-Up Your Code-Fu With Chuck Norris (and ReSharper, VsVim and NCrunch)
vintharas
0
1.3k
The Web Of The Future - Knockout Components
vintharas
1
1.2k
Introduction to RavenDB
vintharas
0
1.3k
The Path to Jedi Text Editing With VIM - Padawan Edition
vintharas
0
1.8k
TypeScript
vintharas
3
330
Other Decks in Programming
See All in Programming
設計の知識と技能で駆動するソフトウェア開発
masuda220
PRO
18
10k
コミュニティに参加したことで起きた変化
ohmori_yusuke
3
130
Go1.22からの疑似乱数生成器について/go-122-pseudo-random-generator
convto
1
160
document.write再考
brn
5
2.5k
生成 AI の中身を覗いてみよう〜基礎から医療現場での応用まで〜
soh9834
2
760
LLMチャットボットのアプリケーション設計Tips
os1ma
4
660
受託開発でGitLab CI を活用していく
xiombatsg
1
110
Material 3で Material 2ぽい見た目にする
numeroanddev
2
250
15分間でふんわり理解するDocker @ Matsuriba MAX
ukwhatn
PRO
1
340
Ruby製社内ツールのGo移行
bgpat
2
260
クソコード動画『カプセル化 Mk-II』 で考える 上手くカプセル化できない理由 / encapsulation2
minodriven
11
7.8k
PHPerKaigi 2024〜10年以上動いているレガシーなバッチシステムを Kubernetes(Amazon EKS) に移行する取り組み〜
tshinowpub
1
220
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
227
130k
Agile that works and the tools we love
rasmusluckow
323
20k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
18
6.8k
The Cost Of JavaScript in 2023
addyosmani
13
3.7k
Writing Fast Ruby
sferik
619
59k
Fashionably flexible responsive web design (full day workshop)
malarkey
397
65k
Typedesign – Prime Four
hannesfritz
36
2k
Producing Creativity
orderedlist
PRO
335
39k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
355
22k
How STYLIGHT went responsive
nonsquared
92
4.7k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
113
18k
Designing Experiences People Love
moore
135
23k
Transcript
P2P Code Academy Becoming a C# Warrior-Poet or Tips and
Tricks To Improve Code Readability in C# 4 30th March
C#
Outline • Object Initializers • Named Arguments • Extension Methods
• LINQ
Ye Olde Classic Constructor
Object Initializers vs Constructors
Object Initializers Uses Default Constructor!
Object Initializers. Benefits • Improved Readability • Less boiler-plate code
– Don’t even need a constructor!
DEMO OBJECT INITIALIZERS
Collection Initializers
Named Arguments • Explicitly name method arguments
Named Arguments. Benefits What the heck is true?
Named Arguments. Benefits
Extension Methods Add methods to existing types: • No need
to create derived type • No need to re-compile existing type • No need to modify original type • Just static methods in disguise!
Extension Methods. Syntax Special use of keyword this Look like
instance methods!
Extension Methods Add a method to a primitive type Adding
this method to the string class
Extension Methods Add a method to a primitive type Before
After
DEMO EXTENSION METHODS
Extension Methods Add a method to a compiled custom type
LINQ Query language within C# and VB.NET • Very Expressive
• Extensible • Integrated – LINQ to Objects – LINQ to SQL – LINQ to XML – LINQ to Entities
LINQ. Example Filtering a collection (People older than 30)
LINQ. Example Query Syntax Method Chain Syntax
DEMO LINQ
Summary • Object Initializers • Named Arguments • Extension Methods
• LINQ
If you put it all together... Sonnet 138. The Passionate
Pilgrim C# version while (myLove.Swears(that: ”She is made of truth”)) { do I.Believe(her); while (she.Lies()) she.Might(s => s.Think(I == ”some untutored youth”)); she.Might(s => s.Think(I == ”unskillful”)); ... }
C#
If you want to know more…
References • Object and Collection Initializers http://bit.ly/csharp-object-collection-initializer • Named Arguments
http://bit.ly/csharp-named-arguments • Extension Methods http://bit.ly/csharp-extension-methods • LINQ http://bit.ly/linq-language-integrated-query
Thank you