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

Slides:



Advertisements
Similar presentations
Developer Knowledge Sharing Eric Sun Dec, What programming language did you learn in school and since then? Now, its time to refresh …
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Writing Modern C++ Marc Grégoire Software Architect April 3 rd 2012.
Software Testing with Visual Studio 2013 & Team Foundation Server 2013 Benjamin Day.
Real World Scrum with TFS2013 Benjamin Day. Brookline, MA Consultant, Coach, & Trainer Microsoft MVP for Visual Studio ALM Team Foundation Server, Software.
Design for Testability: Mocks, Stubs, Refactoring, and User Interfaces Benjamin Day benday.com |
Team Foundation Server 2010 Builds: Understand, Configure, and Customize Benjamin Day benday.com |
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Trey Mack James Moore Osa Osar-Emokpae
History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow 
C#/.NET Jacob Lewallen. C# vs.NET.NET is a platform. Many languages compile to.NET: –VB.NET –Python.NET –Managed C++ –C#
ASP.NET Programming with C# and SQL Server First Edition
Intro to C# Language Richard Della Tezra IS 373. What Is C#? C# is type-safe object-oriented language Enables developers to build a variety of secure.
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Design for Testability: Mocks, Stubs, Refactoring, and User Interfaces Benjamin Day.
 Introduction  What is LINQ  Syntax  How to Query  Example Program.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
@benday #vslive Better Unit Tests through Design Patterns: Repository, Adapter, Mocks, and more… Benjamin
Eric Vogel Software Developer A.J. Boggs & Company.
Neal Stublen Class Objectives  Develop an understanding of the.NET Framework  Gain proficiency using Visual Studio  Begin learning.
@benday #vslive Automated Build, Test & Deploy with TFS, ASP.NET, and SQL Server Benjamin
BIM313 – Advanced Programming Techniques Object-Oriented Programming 1.
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
Top 10 Ways to Go from Good to Great Scrum Master Benjamin Day.
Team Foundation Server 2012 Builds: Understand, Configure, and Customize Benjamin Day.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
Introduction to C# C# is - elegant, type-safe, object oriented language enabling to build applications that run on the.NET framework - types of applications.
Introduction to Building Windows 8.1 & Windows Phone Applications.
How to be a C# ninja in 10 easy steps Benjamin Day.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
Introduction to Exception Handling and Defensive Programming.
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
Hoang Anh Viet Hà Nội University of Technology Chapter 1. Introduction to C# Programming.
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
C++ Memory Overview 4 major memory segments Key differences from Java
Copyright © Curt Hill Structured Data What this course is about.
Introduction to C#. Why C#? Develop on the Following Platforms ASP.NET Native Windows Windows 8 / 8.1 Windows Phone WPF Android (Xamarin) iOS (Xamarin)
Zero to Hero: Untested to Tested with Visual Studio Fakes Benjamin
Bill Campbell, UMB Microsoft's.NET C# and The Common Language Runtime.
Managing C++ CHRIS DAHLBERG MID-TIER DEVELOPER SCOTTRADE.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Introduction to Object-Oriented Programming Lesson 2.
Object Oriented Software Development 4. C# data types, objects and references.
Satisfy Your Technical Curiosity C# 3.0 Raj Pai Group Program Manager Microsoft Corporation
04 |Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio Ben Riga
Real World SQL Server Data Tools Benjamin
CIS 200 Test 01 Review. Built-In Types Properties  Exposed “Variables” or accessible values of an object  Can have access controlled via scope modifiers.
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Benjamin Day Get Good at DevOps: Feature Flag Deployments with ASP.NET, WebAPI, & JavaScript.
Benjamin Unit Testing & Test-Driven Development for Mere Mortals.
Benjamin Day Role-based Security Stinks: Better Authorization in ASP.NET.
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
DevOps with ASP.NET Core and Entity Framework Core
Better Unit Tests through Design Patterns: Repository, Adapter, Mocks, and more… Benjamin
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2014
CIS 200 Test 01 Review.
Module 5: Common Type System
Upgrading Your C# Programming Skills to Be a More Effective Developer
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
CS360 Windows Programming
Unit Testing & Test-Driven Development for Mere Mortals
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
.NET and .NET Core 9. Towards Higher Order Pan Wuming 2017.
Get Good at DevOps: Feature Flag Deployments with ASP
AVG 24th 2015 ADVANCED c# - part 1.
Implementing Security in ASP.NET Core: Claims, Patterns, and Policies
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2018
Presentation transcript:

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

Brookline, MA Consultant, Coach, & Trainer Microsoft MVP for Visual Studio ALM Team Foundation Server, Software Testing, Scrum, Software Architecture Scrum.org Classes –Professional Scrum Developer (PSD) –Professional Scrum Foundations (PSF)

Online courses at Pluralsight.com

Why did I write this talk?

TOP 10 THINGS

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 11. Async & Await

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

#1: Be humble.

Be humble. Software is complex. We developers… –…want to please –…think we’re awesome –…almost always underestimate

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.

Tip for managers. Your devs are afraid of you.

Tip for executives. Your devs are afraid of you. Your project managers are afraid of you. Your project managers are afraid of the devs.

“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.

#2: Remember Object-Orientation

Object-Oriented Principles The 4 tenets. What are they? Encapsulation Polymorphism Inheritance Abstraction

#3: Write less code

Save some typing.

Less is more. (as long as it’s readable)

Everything you write has to be maintained.

Whatever has to be maintained is “inventory.”

var vs. object

Auto-Implemented Properties

Read-Only Auto-Implemented Properties

…and now I’m going to contradict myself.

Avoid ternary operators

#4: Value types vs. reference types

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

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

#5: Exception Handling

Throw vs. throw ex throw;throw ex;

#6: Generics

What are generics? Syntax that allows you to use similar functionality with different types in a type- safe way Implementation is the same Data types are different

ViewModelField DomainObjectManager

#7: Collections

What is a Collection? Data type for organizing lists of objects Similar to an array

Part of the.NET framework 5 namespaces

Array vs. List Array vs. List Array Size defined when created List Automatically expands

ArrayList vs. List ArrayList vs. List ArrayList Not type-safe Everything is an object Watch out for boxing / unboxing List Type-safe Everything must be an instance of T

#8: IDisposable, Using, and Garbage Collection

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.

IDisposable

IDisposable: Custom Cleanup Gets called when the Garbage Collector is disposing your object Add custom logic For example, close any open database connections

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

Wrap database connections in ‘using’ blocks Most database classes implement IDisposable

Why should you wrap calls to database object in ‘using’ statements?

But there’s a catch.

The Garbage Collector doesn’t call IDisposable.Dispose().

If you want to be bulletproof…

…implement IDisposable along with a Destructor.

#9: LINQ

LINQ Language-Integrated Query Enables SQL-like querying of objects via IEnumerable

LINQ Stuff Operators select from where orderby Useful functions FirstOrDefault() First() Min() Max() Count() Skip() Take() Reverse() Sum()

(Code Demo: LinqSample.cs)

#10: Lambda expressions

What’s a “lambda expression”? Anonymous functions Helpful for delegates

(Code Demos: LambdaExpressionSample.cs & LambdaExpressionForm.cs)

#11: Async & Await

Async programming is a pain in the donkey.

I complain about discuss this in a couple of articles.

us/magazine/jj aspx us/magazine/jj aspx

Why? Async calls are really 3 calls. 1) the initiator 2) the do-er 3) the return handler They don’t share the same call stack.

Who cares? Since they don’t share the same call stack you can’t… …return values using the return keyword …throw an exception –(DOH!!!)

Async & Await Async is all over the place in Windows Phone, Windows Store / WinRT, and Silverlight Async, Await, Task, Task help take the pain out of async programming. (New for Visual Studio 2012 &.NET 4.5)

How does async & await work?

Basically, async & await injects a lot of glue to knit the calls together.

Additional Reading Essential C# 5.0 by Mark Michaelis Great overview of the language

Additional Reading CLR via C# by Jeffrey Richter What’s going on under the hood of C# and the.NET Framework

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 11. Async & Await

Thank you. |