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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Jaime
June 10, 2012
Programming
1.1k
5
Share
Tips and Tricks To Improve Code Readability in C#
Jaime
June 10, 2012
More Decks by Jaime
See All by Jaime
Mastering the Arcane Art of JavaScriptmancy @ DevSum
vintharas
1
930
From Angular 1 to Angular 2
vintharas
0
2.2k
Mastering The Arcane Art of JavaScriptmancy - Swetugg Edition
vintharas
1
1.6k
Mastering the Arcane Art of JavaScript-mancy
vintharas
0
3.9k
Level-Up Your Code-Fu With Chuck Norris (and ReSharper, VsVim and NCrunch)
vintharas
0
1.4k
The Web Of The Future - Knockout Components
vintharas
1
1.3k
Introduction to RavenDB
vintharas
0
1.4k
The Path to Jedi Text Editing With VIM - Padawan Edition
vintharas
0
1.9k
TypeScript
vintharas
3
400
Other Decks in Programming
See All in Programming
サークル参加から学ぶ、小さな事業の回し方
yuzneri
0
140
PHPでローカル環境用のSSL/TLS証明書を発行することはできるのか? #phpconkagawa
akase244
0
350
【26新卒研修資料】TDD実装演習
dip_tech
PRO
0
170
Lightning-Fast Method Calls with Ruby 4.1 ZJIT / RubyKaigi 2026
k0kubun
3
2.6k
いつか誰かが、と思っていた フロントエンド刷新5年間の実践知
kiichisugihara
1
260
AI時代になぜ書くのか
mutsumix
0
210
Explore CoroutineScope
tomoeng11
0
170
SREに優しいTerraform構成 modulesとstateの組み方
hiyanger
2
170
AI時代のエンジニアリングの原則 / Engineering Principles in the AI Era
haru860
0
1.1k
cloudnative conference 2026 flyle
azihsoyn
0
120
WebAssembly を読み込むベストプラクティス 2026年春版 / Best Practices for Loading WebAssembly (Spring 2026)
petamoriken
5
1.1k
ついに来た!本格的なマルチクラウド時代の Google Cloud
maroon1st
0
390
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
170
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
280
Into the Great Unknown - MozCon
thekraken
41
2.4k
Ruling the World: When Life Gets Gamed
codingconduct
0
220
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
4 Signs Your Business is Dying
shpigford
187
22k
A better future with KSS
kneath
240
18k
Side Projects
sachag
455
43k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.6k
Documentation Writing (for coders)
carmenintech
77
5.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.4k
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