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
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
860
From Angular 1 to Angular 2
vintharas
0
2.1k
Mastering The Arcane Art of JavaScriptmancy - Swetugg Edition
vintharas
1
1.6k
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.4k
The Web Of The Future - Knockout Components
vintharas
1
1.2k
Introduction to RavenDB
vintharas
0
1.4k
The Path to Jedi Text Editing With VIM - Padawan Edition
vintharas
0
1.8k
TypeScript
vintharas
3
370
Other Decks in Programming
See All in Programming
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
390
MDN Web Docs に日本語翻訳でコントリビュートしたくなる
ohmori_yusuke
1
120
猫と暮らす Google Nest Cam生活🐈 / WebRTC with Google Nest Cam
yutailang0119
0
120
20250704_教育事業におけるアジャイルなデータ基盤構築
hanon52_
5
790
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
170
PipeCDのプラグイン化で目指すところ
warashi
1
280
ニーリーにおけるプロダクトエンジニア
nealle
0
840
AIともっと楽するE2Eテスト
myohei
6
2.6k
Team operations that are not burdened by SRE
kazatohiei
1
310
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
21
4k
Python型ヒント完全ガイド 初心者でも分かる、現代的で実践的な使い方
mickey_kubo
1
120
効率的な開発手段として VRTを活用する
ishkawa
0
140
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Visualization
eitanlees
146
16k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Six Lessons from altMBA
skipperchong
28
3.9k
Statistics for Hackers
jakevdp
799
220k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
46
9.6k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
Building Applications with DynamoDB
mza
95
6.5k
Typedesign – Prime Four
hannesfritz
42
2.7k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.9k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
281
13k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
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