Length: 5 Days
Introduction to C#
Candidates for this course ideally should have had one to two years’ experience in programming either in other programming languages or scripting languages (including PowerShell).
There is a lab 0, which encourages students to install Visual Studio 2017 Community (the free edition of Visual Studio 2017), this must be installed on Windows 8 and higher—Windows 10 is recommended highly. Also, the course has been tested on Visual Studio 2017 Enterprise, so students with access to that edition may use that in preference to Visual Studio 2017 Community.
WHAT YOU’LL LEARN
After completing this course, students will be able to:
· Identify the core components of programming—memory management, control-of-flow and code reuse
· Use C# language constructs including loops, decisions and error handling
· Use and create struct and enum types
· Work with arrays
· Design classes including class members such as methods, properties, indexers, events and delegates
· Create simple object hierarchies using inheritance
· Create polymorphic structures using interfaces
· Design exception hierarchies
· Explain the basic principles of unit testing
· Explain boxing and unboxing of value types and identify when they occur
· Explain and modify extension methods
· Explain operator overloading
· Use appropriate collection types to store array-like data flexibly
· Explain memory-management including the use of the stack and managed heap; garbage collection; destructors; and implement the IDisposable pattern in classes
· Explain the .Net concept of an assembly as a unit of deployment and versioning
· Explain how delegate types delegate invocation to a call-back method
· Explain and use (simple) lambda expressions
· Explain the eventing process for inter-class communication and implement simple event-driven coding patterns
· Explain the concept of asynchronous programming using threads; implement asynchronous methods in code; and explain the use of the BackgroundWorker class to simplify asynchronous programming
· Explain the concept of language integrated queries (LINQ) and write simple LINQ queries using extension methods and the declarative query syntax
· Work with streams including reading and writing to files, isolated storage, network, compression and encryption
· Explain and implement serialization for object persistence
· Explain basic ASP.Net concepts including model-view-controller (MVC) version 5 concepts of models, controllers and views including razor syntax
· Explain the basic concepts of web services in the context of Windows Communication Foundation (WCF) services
WHO SHOULD ATTEND
This course is intended for people with some programming or scripting experience in other languages who want to learn C# as a programming language; a typical candidate for this course is likely to be someone with maintenance programmer in their job description—someone who is exposed to a range of code to modify it for changing business requirements.
Module 1: Programming
This module looks at the concept of computer programming in the context of C# as a language to program in. The topics covered require no previous experience, however, they will be familiar to anyone who has performed computer programming tasks previously in another programming language.
• Memory management
• Control of flow
• Code reuse
• Guided tour of visual studio 2017
Module 2: C# language
This module builds on the programming concepts in the previous module and introduces C# as a language. The content has frequent references to the C# Language Specification, as this is authoritative when examining the language; the references provided are intended to assist understanding and are therefore refer to the simpler parts of the specification.
• Data types
Module 3: Data types and arrays
This module presents the data types available in C# and introduces value types; it provides a superficial introduction to reference types and concludes with an explanation of arrays. Arrays are memory structures that hold multiple copies of a type that we can iterate over using for and for each loops. Later in the course we will look at collections, which while similar to arrays are more flexible.
• Value types
• Reference types
Module 4: Classes and Objects
This module looks at the distinction between classes and objects (which are often confused). We explore what a class is and the key elements classes should have. We also look at objects and the concept of instantiation (construction) of objects from classes. Later, in Module 9, we will look at the destruction of objects.
• Classes, objects and types
• Class methods
• Partial keyword
• System.object class
Module 5: Inheritance
This module looks at inheritance and related topics in C#.
Inheritance is fundamental to any object model or class hierarchy and is particularly useful in facilitating code reuse. We move on to look at abstraction and encapsulation (which we have already touched on in the previous module) and finish up looking at the static keyword including how it is used in an inheritance hierarchy.
• Inheritance in C#
• Abstraction and encapsulation
• Static keyword
Module 6: Interfaces, exceptions and unit testing
The concept of an interface introduces a new type, the interface type, to the C# language; customized exception hierarchies are common object hierarchies programmers develop, so this topic is included by way of illustration and reinforcement of the previous module’s concepts; unit testing is a common methodology used to ensure your code is robust and performs according to specification.
• Unit testing
Module 7: Value types
In this module, we examine value types—the data structures for C#. Initially, we look at the base class ValueType and how it relates to value types in general; we examine boxing and unboxing value types to (and from) reference types; the module moves on to discuss struct types and enum types; and concludes with an optional [advanced] discussion on operator overloading.
• Boxing and unboxing
• Operator overloading
Module 8: Collections and generics
This module starts by explaining the generic framework in C# especially including type parameters and their use in generic classes, methods and interfaces. The discussion continues to include [non-generic] collections and generic collections to use as array-like containers for unknown numbers of elements. Finally, the module concludes with an [advanced] optional lesson on variance and how it is applied to generic interfaces in C#.
• Generics in C#
• Generic classes
• Generic methods
• Generic interfaces
• Collections and generic collections
Module 9: Memory management and assemblies
This module starts by reintroducing object instantiation developing the discussion into greater detail than covered in module 1. To complete the object life-cycle, we discuss garbage collection and look at the garbage collector class. This leads to discussing object destructor code and proposes the dispose pattern as an alternative adjunct to destructor code. Finally, we discuss assemblies as the unit of output from Visual Studio, when we compile our code.
• Object instantiation
• Garbage collection
• Dispose pattern
Module 10: Delegates and events
In this module we discuss loose coupling, coding for change programmatically; using delegates as one way to implement loose coupling by delegating to a method; how events invoke a delegate; and that lambda expressions are delegates disguised as anonymous methods.
• Loose coupling
• Lambda expressions
Module 11: Asynchronous programming
In this module on asynchronous programming, we discuss executing code on a separate thread and examine the Thread class which supports this; we examine the async and await keywords as a pattern in the C# language that supports asynchronous programming; optionally, we examine the Task class as another pattern of performing asynchronous programming; and conclude by looking at the BackgroundWorker class for responsive user interfaces.
• Threads and threading
• Thread class
• Aynsc and await keywords
• Task class
• Backgroundworker class
Module 12: LINQ and the Entity Framework
In this module, we introduce LINQ as a technique to query in-memory data inside our application; we then turn to discussing the entity framework as one way to interact with data outside our application.
• Entity framework
Module 13: Streams and I/O
In this module, we introduce input/output (I/O) by examining classes and techniques related to the System.IO namespace; firstly, we examine the support for files, directories and the file system in general; we examine streams and readers and writers that interact with streams; we then look at specialized streams for compression and encryption; we discuss isolated storage as an alternative to accessing the whole file system; we provide an introduction to networking classes; and conclude with a discussion on persisting class data through serialization.
• Files, directories and the file system
• Streams, readers and writers
• Compression and encryption
• Isolated storage
• Network classes
Module 14: ASP.Net and MVC
In this module, we introduce web development using C# and Visual Studio 2017. The module commences with a high level discussion on web development and common methodologies before moving on to an introductory discussion of the model view controller pattern (MVC) for ASP.Net web development.
This is a big topic—one introductory module can provide only the briefest of treatments of the topic. Our objective is to provide some exposure to these technologies so there is some familiarity should you find yourself working on a project that uses them.
• Model-view-controller (MVC)
Module 15: Windows Communication Foundation (WCF) Services
Windows Communication Foundation (WCF) was introduced into .Net Framework version 3.0 to provide a suite of technologies to assist building distributed applications including web services.