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
5
1.1k
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
910
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
390
Other Decks in Programming
See All in Programming
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
310
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
7.4k
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
7
2.4k
SourceGeneratorのススメ
htkym
0
200
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
CSC307 Lecture 08
javiergs
PRO
0
670
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
590
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
1k
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
140
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
180
余白を設計しフロントエンド開発を 加速させる
tsukuha
7
2.1k
Apache Iceberg V3 and migration to V3
tomtanaka
0
160
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
54
8k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
780
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
330
[SF Ruby Conf 2025] Rails X
palkan
1
760
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
650
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
200
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.1k
A better future with KSS
kneath
240
18k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.3k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1.1k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
250
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