Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
1k
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.5k
The Web Of The Future - Knockout Components
vintharas
1
1.3k
Introduction to RavenDB
vintharas
0
1.5k
The Path to Jedi Text Editing With VIM - Padawan Edition
vintharas
0
1.9k
TypeScript
vintharas
3
430
Other Decks in Programming
See All in Programming
wkhtmltopdfの次どうするか問題2026
willnet
2
1.9k
SREの越境 / SRE Collaboration
y0hgi
2
300
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
720
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
7.9k
JRuby: Past, Present, and Future
headius
0
220
気持ちぃ〜角丸 Squircle
ryu1013
0
120
パーソナライズPodcastを作った話
repunit11
0
130
複雑なUIコンポーネントとの ⻑い付き合い⽅:波及するバグからテスト戦略を経て、安全な再設計へ
mixplace
0
130
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
120
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
350
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
110
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
120
Featured
See All Featured
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
610
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Building Applications with DynamoDB
mza
96
7.2k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
From π to Pie charts
rasagy
1
390
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
610
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
320
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