What you will learn in this course
You'll get answers to these questions:
- How do I make good design decisions (e.g., interface vs. abstract class, or property vs. field)?
- How much overhead do CLR services like runtime compilation and garbage collection add?
- How do I decompose my application into a main .exe and supporting .dlls and deploy the application?
- What types are available in the .NET Framework class library
Come and learn how to use C# to build .NET applications.
- Examine core language features such as types, variables, and control constructs
- Use object-oriented features such as class, interface, protection, and inheritance
- Perform error notification and error handling using exceptions
- Use properties to implement the private data/public accessor pattern
- Use namespaces to group related types
- Use delegates and events to implement callbacks
- Override Object class methods such as ToString
- Avoid dll conflicts during deployment
- Use dynamic binding and polymorphism to write generic code (i.e., less code!)
- Distinguish between "implementation inheritance" and "interface inheritance"
- Use ADO.NET to connect to SQL Server and run a simple query
- Build a basic Windows Forms GUI
Course outline and topics
C# is one of the primary languages used to develop applications for the Microsoft .NET platform. C# is the language of choice for C, C++, and Java programmers moving to .NET. It is also attractive to those coming from other backgrounds because it combines the concise syntax common to all C-family languages with the power, safety, and rapid application development traditionally enjoyed by the VB world.
C# provides all the features expected of a modern object-oriented programming language: class, interface, inheritance, polymorphism, encapsulation, etc. In addition, the language offers some new and powerful innovations such as properties, indexers, delegates, events, and attributes.
Foundations of C# and the .NET Framework spends about half its time on the C# language. It moves quickly through the basics so it can cover the most important features in depth. Newer features such as generics, partial classes, static classes, global namespace qualification, etc. are integrated throughout the course.
To put the language in context, the course includes several .NET platform topics. We discuss the .NET type system (the universal base class Object and reference types). We survey the software development cycle (code, compile, deploy, execute). We look at platform support for execution (Common Language Runtime, garbage collection, exceptions). We finish with some of the most useful topics from the .NET Framework class library (string handling, Silverlight GUI, and SQL Server database access).
We begin with a brief overview of the languages, libraries, servers, services, and tools that make up the Microsoft .NET platform.
.NET Execution Model
This module examines the .NET software development model: C# source code, compiler, intermediate language, .exe/.dll files, and the Common Language Runtime execution engine.
Here we see how to build and run the simplest type of .NET executable: a console application. Console applications are common for development tools such as compilers and linkers. They also work well for utilities like ftp, ipconfig, etc.
Here we create and use a dynamic-link library. Libraries let you split an application into pieces that you build and version separately. They help eliminate repeated code since multiple executables can share a library.
This section covers the core C# features that will be used by almost every program: application entry point, predefined data types, variables, basic input and output, operators, arrays, control constructs, comments, etc.
A class is a key object-oriented programming concept and the primary unit of coding in C#. This section introduces classes with coverage of instance fields and methods, access control, and object creation.
Initialization of variables is important for program correctness. C# provides excellent support for initialization through well-defined default values, variable initializers, and instance constructors.
Properties model the characteristics or traits of a type. They make the client code clean and simple while allowing class designers to maintain encapsulation and execute validation code.
The static keyword is used with fields, methods, and types. Static fields are used to implement shared resources. Static methods are useful as utilities where the full power of an instance method is not required. Static types are convenient containers for static fields and methods. Here we discuss how to declare and use static types and members. We cover the three initialization options for static fields (default values, static variable initializers, and static constructor).
Reference types are implemented as reference/object pairs. An object is created using the "new" operator and is subsequently accessed through a reference. Here we discuss a number of issues surrounding references: assignment, parameter passing, aggregation, array, null, and garbage collection.
Implementation Inheritance 1
Inheritance provides a powerful tool for object-oriented programmers to model their application domain. Here we discuss the syntax and the meaning of inheritance: placing common code in the base class, adding new members to the derived class, access within an inheritance hierarchy, and constructor chaining.
Implementation Inheritance 2
This section covers many issues that arise in the presence of inheritance: type compatibility, type conversion, method binding, method overriding, and abstract methods. We discuss how to use dynamic binding to achieve polymorphic behavior.
An interface defines a contract that types can agree to support. Here we discuss the details of defining and implementing interfaces, including how to write generic code against an interface and how to use inheritance with interfaces.
C# has a unified type system: all types inherit from the library class Object. This section discusses the details of the Object class including a survey of the methods provided, when and how to override those methods, and how to use an Object reference as a generic handle.
This module describes the C# error notification mechanism of exceptions. We show how to generate an exception, how to handle an exception, control flow when an exception is thrown, services offered by the exception classes in the .NET Framework class library, and how to implement a custom exception type.
Namespace provides the ability to group logically related types and to separate types with the same name into different scopes. In this section, we present how to create a namespace, how to access a type defined inside a namespace, and how to apply the using keyword to obtain convenient shorthand access to namespace members.
Most .NET types use events to report state change. For example, GUI controls like buttons, trees, lists, etc. use events to report user actions such as button click, list selection, etc. The FileSystemWatcher class reports directory activity through the Changed, Created, and Deleted events. In this section, we show how to use C# to subscribe to and unsubscribe from .NET events.
Windows Forms provides support for building traditional forms-based
applications that run locally on the client machine. This module explains
the basics of Windows Forms application development with a survey of common controls and a detailed look at event handling.
ADO.NET - Introduction
This module looks at the ADO.NET data access model. It shows how to use SqlConnection to connect to SQL Server, SqlCommand to execute queries, and SqlDataReader to process a result set.
Generic code is better than specific code - it works for many cases so we avoid writing the cases individually. C# gives us several ways to write generic code: polymorphism, reflection, and generics. Each technique has its place. Generics are for code that is independent of type; that is, code that does not need to know the data type it is working with. The classic examples are collections such as hash tables, trees, and linked lists where the code to build the structure is independent of the type stored inside. C# generics let us write types and methods that are parameterized by type - the type is a parameter supplied by the client. This module shows how to define generic types and methods.
Here we examine the capabilities of two important classes supplied in the .NET Framework class library: String and StringBuilder. Together, the two classes provide efficient support for the most common types of string manipulation.
An assembly is the basic unit of versioning, security, and deployment for the CLR. Here we discuss how to create an assembly, how to build applications that consist of multiple assemblies, and how to deploy multi-assembly applications.
Appendices (not taught)
The course materials also include the following extra modules:
- Preprocessor: overview of available preprocessor directives
- Type Conversion: user-defined type conversion operators
- Event Publication: how to raise a custom event
- Equals: how and when to override the Object.Equals method
- Clone: how and when to implement cloning
- Finalization: cleanup of unmanaged resources using destructors and IDisposable
- Input and Output: disk file I/O
- Legacy Collections: object-based collections (superseded by generics)
- Indexers: allow access to collections with square brackets [ ]
- Operator Overloading: how to overload operators to work with your custom types
- ADO.NET Stored Procedure: how to call a stored procedure
- ADO.NET Disconnected Data: load a client-side copy of your data, modify, and update
- ADO.NET config file: how to store connections strings in a config file
- ADO.NET Data Provider Factories: generic coding with ADO.NET
- Transactions Introduction: overview of transactions and the TransactionScope class
- Generic Constraints: constrain the types usable with a generic
- Value Types: how to create custom structs when you need types with value semantics
- Constants: how to code symbolic constants with const, readonly, and enum
- Silverlight: Rich-web, XAML-based UI framework