How to be a C# ninja in 10 easy steps. Benjamin Day

Similar documents
Test Your XAML-based Windows Store Apps with Visual Studio 2013 Benjamin Day

Get Good at DevOps: Feature Flag Deployments with ASP.NET, WebAPI, & JavaScript

The C# Programming Language. Overview

Programming in Visual Basic with Microsoft Visual Studio 2010

Microsoft Visual C# Step by Step. John Sharp

Introduce C# as Object Oriented programming language. Explain, tokens,

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

Microsoft. Microsoft Visual C# Step by Step. John Sharp

Programming in C# with Microsoft Visual Studio 2010

Course Hours

Which one? It all comes down to complexity. Scrum - Kanban Cage Match. Kanban. Scrum Ben Day. The Tale of the Tape. Scrum and Kanban Cage Match

10266 Programming in C Sharp with Microsoft Visual Studio 2010

Chapter 1 Getting Started

Top 7 Lessons From My First Big Silverlight Project

Dot Net Framework 4.0: Advanced Microsoft C#.NET Web Development

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

CHAPTER 1: INTRODUCING C# 3

"Charting the Course... MOC Programming in C# with Microsoft Visual Studio Course Summary

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio

Introduction to Microsoft.NET Programming Using Microsoft Visual Studio 2008 (C#) Course Overview. Prerequisites. Audience.

17 Roberts St #2 Brookline, MA

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

C# Programming in the.net Framework

C# Programming. Unit 1: Introducing C# and the.net FrameworkThis module explains the.net Framework, and using C# and

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com

Prerequisites: The student should have programming experience in a high-level language. ITCourseware, LLC Page 1. Object-Oriented Programming in C#

Course Syllabus C # Course Title. Who should attend? Course Description

.Net. Course Content ASP.NET

C#: framework overview and in-the-small features

JAVA An overview for C++ programmers

Previous C# Releases. C# 3.0 Language Features. C# 3.0 Features. C# 3.0 Orcas. Local Variables. Language Integrated Query 3/23/2007

Object-Oriented Programming

Introduction To C#.NET

C#.NET TRAINING / /

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#)

TECHNOLOGIES. Kick Starting OOPS &.Net Encapsulation Ø Class Ø Struct Ø Interface, Ø Enum Ø Abstraction Ø Access modifiers in.net

C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017

D Programming Language

Object-Oriented Programming in C# (VS 2015)

DOT NET COURSE BROCHURE

Learn to develop.net applications and master related technologies.

Object-Oriented Programming in C# (VS 2012)

C# Programming: From Problem Analysis to Program Design. Fourth Edition

Life as a Service. Scalability and Other Aspects. Dino Esposito JetBrains ARCHITECT, TRAINER AND CONSULTANT

DIPLOMA IN PROGRAMMING WITH DOT NET TECHNOLOGIES

.Net Technologies. Components of.net Framework

This tutorial has been prepared for the beginners to help them understand basics of c# Programming.

Introducing C# and the.net Framework

Contents. LINQ for Visual C# 2008 i

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

C# s A Doddle. Steve Love. ACCU April 2013

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including:

Programming C# 5.0. Ian Griffiths O'REILLY' Beijing Cambridge * Farnham Kbln Sebastopol Tokyo

Visual C# 2012 How to Program by Pe ars on Ed uc ati on, Inc. All Ri ght s Re ser ve d.

Visual C# 2008 How to Program, 3/E Outline

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

DOT NET Syllabus (6 Months)

Deitel Series Page How To Program Series

Migrate Your Skills to Microsoft.NET Framework 2.0 and 3.0 using Visual Studio 2005 (C#)

Item 18: Implement the Standard Dispose Pattern

What goes inside when you declare a variable?

inside: THE MAGAZINE OF USENIX & SAGE August 2003 volume 28 number 4 PROGRAMMING McCluskey: Working with C# Classes

Diploma in Microsoft.NET

Rx is a library for composing asynchronous and event-based programs using observable collections.

Learning to Program in Visual Basic 2005 Table of Contents

.NET Advance Package Syllabus

DAD Lab. 1 Introduc7on to C#

Variable Scope The Main() Function Struct Functions Overloading Functions Using Delegates Chapter 7: Debugging and Error Handling Debugging in Visual

Runtime code generation techniques in real life scenarios

Unity Tutorial. Fall /15-666

Interview Questions I received in 2017 and 2018

Introduction to programming

Binghamton University. CS-211 Fall Object Orientation

BUILDING APPLICATIONS USING C# AND.NET FRAMEWORK (OBJECT-ORIENTED PROGRAMMING, X428.6)

Programming in C# (20483)

Course Description. Learn To: : Intro to JAVA SE7 and Programming using JAVA SE7. Course Outline ::

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Apex TG India Pvt. Ltd.

Index COPYRIGHTED MATERIAL

CSCI-1200 Data Structures Fall 2011 Lecture 24 Garbage Collection & Smart Pointers

Effective C# (Covers C# 4.0): 50 Specific Ways to Improve Your C#

Bart De Smet C# 4.0 UNLEASHED

20483BC: Programming in C#

System.Collections.Generic.SortedSet: who needs another collection anyway?

SECURED PROGRAMMING IN.NET DETAILED TRAINING CONTENT INDUSTRIAL TRAINING PROGRAM ( )

CS121/IS223. Object Reference Variables. Dr Olly Gotel

Course Status Polymorphism Containers Exceptions Midterm Review. CS Java. Introduction to Java. Andy Mroczkowski

Introduction to Microsoft.NET Framework Programming using VS 2005 (C#)

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

C++11: 10 Features You Should be Using. Gordon R&D Runtime Engineer Codeplay Software Ltd.

Module 1. An Introduction to C# Module 2. Classes and Objects. Vasundhara Sector 14-A, Plot No , Near Vaishali Metro Station,Ghaziabad

Objective-C. Stanford CS193p Fall 2013

C# and Java. C# and Java are both modern object-oriented languages

C# in Depth SECOND EDITION JON SKEET. MANNING Greenwich (74 w. long.)

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

C# Syllabus. MS.NET Framework Introduction

VS08 This One Goes to Going Parallel with PFX, PLINQ, TPL and Async Keywords

Visual Basic 2008 How to Program, 4/E Outline

10264A CS: Developing Web Applications with Microsoft Visual Studio 2010

Transcription:

How to be a C# ninja in 10 easy steps Benjamin Day

Benjamin Day Consultant, Coach, Trainer Scrum.org Classes Professional Scrum Developer (PSD) Professional Scrum Foundations (PSF) TechEd, VSLive, DevTeach, O Reilly OSCON Visual Studio Magazine, Redmond Developer News Microsoft MVP for Visual Studio ALM Team Foundation Server, TDD, Testing Best Practices, Silverlight, Windows Azure http://blog.benday.com benday@benday.com Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 2

Professional Scrum at Scrum.org Professional Scrum Product Owner Product Owners Executives Professional Scrum Master Scrum Masters Professional Scrum Developer.NET or Java Architects Business Analysts DB Specialists Designers Developers Testers Professional Scrum Foundations Everyone 1993-2011 Scrum.org, All Rights Reserved

TOP 10 THINGS Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 4

The List. 1. Be humble 2. Object-orientation 3. Write less code 4. Value Types vs. Reference Types 5. Exceptions 6. Generics 7. Collections 8. IDisposable, using, & garbage collection 9. LINQ 10. Lambda Expressions Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 5

Some extras. 11. Virtual, override, & new() 12. Tune out the static 13. Partial classes & methods 14. Covarience contravariance 15. Named parameters 16. Optional parameters 17. Dynamic keyword Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 6

BE HUMBLE. Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 7

Be humble. Software is complex. We developers want to please think we re awesome almost always underestimate Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 8

Tips. Keep it simple. Expect to make mistakes. Not everyone will understand your abstractions. Favor maintainability over slickness. Write unit tests. Lots of unit tests. Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 9

C# doesn t do Xyz. C# sucks. Lesson I learned. There s a reason it s built that way. Don t fight it. Embrace it. Learn from the design. Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 10

Remember Object-Orientation Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 11

Object-Oriented Principles 4 tenets Encapsulation Polymorphism Inheritance Abstraction Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 12

WRITE LESS CODE Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 13

Save some typing. Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 14

Less is more. (as long as it s readable) Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 15

Everything you write has to be maintained. Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 16

var vs. object Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 17

Auto-Implemented Properties Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 18

Read-Only Auto-Implemented Properties Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 19

Avoid ternary operators Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 20

VALUE TYPES VS. REFERENCE TYPES Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 21

Whuh? Value Types Non-object types Stored in memory stack int, long, char, byte, etc. float, double decimal bool User-defined Structs Enumerations Reference Types Object types Stored in memory heap Variables are pointers to memory location Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 22

Boxing and Unboxing Boxing Process of wrapping a value type in an object reference Unboxing Converting a boxed value type object back into an value type variable Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 23

EXCEPTION HANDLING Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 24

Throw vs. throw ex throw; throw ex; Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 25

GENERICS Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 26

What are generics? Syntax that allows you to use similar functionality with different types in a typesafe way Implementation is the same Data types are different Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 27

ViewModelField<T> DomainObjectManager<T> Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 28

COLLECTIONS

What is a Collection? Data type for organizing lists of objects Similar to an array Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 30

Part of the.net framework 5 namespaces Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 31

Array vs. List<T> Array Size defined when created List<T> Automatically expands Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 32

ArrayList vs. List<T> ArrayList Not type-safe Everything is an object Watch out for boxing / unboxing List<T> Type-safe Everything must be an instance of T Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 33

IDISPOSABLE, USING, AND GARBAGE COLLECTION Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 34

What is Garbage Collection? Background process in.net Determines when an object is not needed Deletes it automagically Frees up memory You worry much less about memory management. Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 35

IDisposable Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 36

IDisposable: Custom Cleanup Gets called when the Garbage Collector is disposing your object Add custom logic For example, close any open database connections Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 37

Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 38

What does the using statement do? Wraps instance of IDisposable for block of code Instance is disposed automatically at the end of the code block Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 39

Wrap database connections in using blocks Most database classes implement IDisposable Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 40

Why should you wrap calls to database object in using statements? Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 41

LINQ Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 42

LINQ Language-Integrated Query Enables SQL-like querying of objects via IEnumerable<T> Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 43

LINQ Stuff Operators select from where orderby Useful functions FirstOrDefault() First() Min() Max() Count() Skip() Take() Reverse() Sum() Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 44

(Code Demo: LinqSample.cs) Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 45

LAMBDA EXPRESSIONS Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 46

What s a lambda expression? Anonymous functions Helpful for delegates Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 47

(Code Demos: LambdaExpressionSample.cs & LambdaExpressionForm.cs) Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 48

Additional Reading Essential C# 4.0 by Mark Michaelis Great overview of the language Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 49

Additional Reading CLR via C# by Jeffrey Richter What s going on under the hood of C# and the.net Framework Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 50

The List. 1. Be humble 2. Object-orientation 3. Write less code 4. Value Types vs. Reference Types 5. Exceptions 6. Generics 7. Collections 8. IDisposable, using, & garbage collection 9. LINQ 10. Lambda Expressions Copyright 2011, Benjamin Day Consulting, Inc. www.benday.com 51

Thank you. http://blog.benday.com http://www.benday.com benday@benday.com