C#

csharp-mini-logoExercises to gain familiarity with the Visual Studio IDE

Working with C# in the Visual Studio IDE – Exercises 1 – Working with Controls
Working with C# in the Visual Studio IDE – Exercises 2 – Working with Controls2
Working with C# in the Visual Studio IDE – Exercises 3 – Working with Data
Working with C# in the Visual Studio IDE – Exercises 4 – Displaying and Formatting Output
Working with C# in the Visual Studio IDE – Exercises 5 – Selection
Working with C# in the Visual Studio IDE – Exercises 6 – Iteration
Working with C# in the Visual Studio IDE – Exercises 7 – Debugging
Working with C# in the Visual Studio IDE – Exercises 8 – Menus, Rich Text Boxes and Dialogues
Working with C# in the Visual Studio IDE – Exercises 9 – Arrays


CIS016-2 Laboratory Exercises

CIS016-2 Lab Exercises 2

CIS016-2 Lab Exercises 3

CIS016-2 Lab Exercises 4


Do you Want a Challenge?

CIS016-2 Lab Project – Game of the Hyperspace Cheese Battle


downloadRob Miles C# Programming Yellow Book
(http://www.robmiles.com/c-yellow-book/)

The C# Yellow Book is used by the Department of Computer Science in theUniversity of Hull as the basis of the First Year programming course. You can download your own copy from here.
This is the 2015 version of the book, the “Bananas” edition.
There are now code samples available which are keyed to the text. You can download them from here. You’ll need Visual Studio 2015 to compile and run them. You can get the Community Edition (it’s free) from here.
There is now a Kindle version of the text available. You can find it here.
You can download the slides, laboratory material and assessed coursework from here.  (49.7MB)

Download the book directly from this website from here (1,560KB)

Download the code samples from this website from here (2,149KB)

Rob Miles’ PowerPoint Lectures
(Useful to scan through)

Week 11 – Starting Programming
Week 11a Our First Programs Notes
Week 11a Our First Programs
Week 11b How Programs Run Notes
Week 11b How Programs Run
Week 11c Making Decisions Notes
Week 11c Making Decisions
Week 11d Writing Programs Notes
Week 11d Writing Programs

Week 12 – Writing Useful Programs
Week 12a Loops Notes
Week 12a Loops
Week 12b Using Loops Notes
Week 12b Using Loops

Week 13 – Methods and Visual Studio
lab4
Week 13a Methods Notes
Week 13a Methods
Week 13b Advanced Methods Notes
Week 13b Advanced Methods

Week 14  – Arrays and Lists
Week 14a Arrays Notes
Week 14a Arrays
Week 14b Lists Notes
Week 14b Lists
Week 14c Data and Types Notes
Week 14c Data and Types

Week 15 – Expressions and Structures
BubbleSort (zipped file)
Week 15a Structures Notes
Week 15a Structures
Week 15b Expresions and Casting Notes
Week 15b Expresions and Casting
Week 15c Enum Notes
Week 15c Enum

Week 16  – Operators Printing and Switches
Week 16a Operator Shorthand Notes
Week 16a Operator Shorthand
Week 16b Neater Printing Notes
Week 16b Neater Printing
Week 16c Switches Notes
Week 16c Switches

Week 17 – Method Libraries
Week 17a Method Libraries Notes
Week 17a Method Libraries

Week 18 – File Handling and Exceptions
Week 18a File Handling Notes
Week 18a File Handling
Week 18b Exceptions Notes
Week 18b Exceptions

Week 28 – Introduction to Objects
W28a Introduction Notes
W28a Introduction
W28b Objects and Structures Notes
W28b Objects and Structures
W28c Objects and References Notes
W28c Objects and References
W28d Storing Data in Objects Notes
W28d Storing Data in Objects

Week 29 – Objects and WPF
W29a References and Arrays Notes
W29a References and Arrays
W29b Constructing Class Instances Notes
W29b Constructing Class Instances
W29c WPF User Interfaces Notes
W29c WPF User Interfaces

Week 30 – Properties Static and Libraries
W30a Properties Notes
W30a Properties
W30b Static and Class Design Notes
W30b Static and Class Design
W30c Programs and Libraries Notes
W30c Programs and Libraries

Week 31 – Creating a Bank
W31a Creating a Bank Notes
W31a Creating a Bank
W31b Saving and Loading a Bank Notes
W31b Saving and Loading a Bank
W31c Object Etiquette Notes
W31c Object Etiquette

Week 32 – XNA
W32a Getting Started with XNA Notes
W32a Getting Started with XNA
W32b Creating Gameplay with XNA Notes
W32b Creating Gameplay with XNA
Assets (zipped file)
Bouncing White Dot (zipped file)
SpriteDemo (zipped file)
SpriteFun (zipped file)

Week 33 – Testing
Introduction Lecture1
Notes Lecture 2 and 3

Week 34 – Inheritance
W34a Inheritance Notes
W34a Inheritance
W34b Abstract Classes and Interfaces Notes
W34b Abstract Classes and Interfaces

Week 35 – Project Starts
W35a Design with Interfaces Notes
W35a Design with Interfaces
W35b Getting Started with Banjos4Hire Notes
W35b Getting Started with Banjos4Hire
W35c Getting Started with Banjo Attack Notes
W35c Getting Started with Banjo Attack

Week 36 – Data Storage and Threads
W36a Generics Lists and Dictionaries Notes
W36a Generics Lists and Dictionaries
W36b Using XML Notes
W36b Using XML
W36c Threads Notes
W36c Threads
RobBlog (zipped file)
ThreadFull (zipped file)
WPFThreadDemo (zipped file)

Week 40 – C# and Other Languages
08120 W40a CSharp and Other Languages Notes
08120 W40a CSharp and Other Languages


C# Language Specification
(https://msdn.microsoft.com/en-us/library/ms228593.aspx)
The C# Language Specification is the definitive source for C# syntax and usage. This spec contains detailed information about all aspects of the language, including many points that the documentation for Visual C# doesn’t cover.


C# Reference
(https://msdn.microsoft.com/en-us/library/618ayhy6.aspx)
This section provides reference material about C# keywords, operators, compiler errors, and warnings.


C# Programming Guide
(https://msdn.microsoft.com/en-us/library/67ef8sbd.aspx)
This section provides detailed information on key C# language features and features accessible to C# through the .NET Framework.

Most of this section assumes that you already know something about C# and general programming concepts. If you are a complete beginner with programming or with C#, you might want to visit the C# Developer Center, where you can find many tutorials, samples and videos to help you get started.

For information about specific keywords, operators and preprocessor directives, see C# Reference. For information about the C# Language Specification, see C# Language Specification.


C# Fundamentals for Absolute Beginners – Microsoft Virtual Academy
(https://www.microsoftvirtualacademy.com/en-us/training-courses/c-fundamentals-for-absolute-beginners-8295?l=bifAqFYy_204984382)


logo5Home and Learn Free C# .NET Tutorial For Beginners
(http://www.homeandlearn.co.uk/csharp/csharp.html)
C# .NET is a very popular and modern programming language from Microsoft. This course is aimed at those who have no experience in the world of programming.

A 483 page eBook is available (http://www.homeandlearn.co.uk/bookshop/csharpbook.htm):

  • Exercises and Projects
  • Answers to Exercises
  • LINQ Functions
  • LINQ Queries
  • Graphics (shapes, brushes, polygons, drawing text)
  • Create your own code libraries
  • C# Charts (Column charts, Line charts, Pie charts)
  • Create your own browser
  • A Picture Viewer Project
  • Image Editing (Image rotation, flipping, cloning, Pixel manipulation)

The eBook (2012) can be downloaded from here


logoC# Tutorial
(http://www.tutorialspoint.com/csharp/)
C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg. This tutorial will teach you basic C# programming and will also take you through various advanced concepts related to C# programming language.

Download a PDF version of the tutorial (2,583KB)


C# Tutorials
(https://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx)
The C# tutorials provide an overview of the basics of the language and identify important language features. Each tutorial includes one or more sample programs. The tutorials discuss the sample code plus provide additional background information. They also link to the corresponding sample abstract topics, where you can download and run the sample programs.

Note   The C# tutorials do not teach how to create a graphical user interface for your program like a Windows Form or a Web Forms page. To get started in that area, see the Visual C# Walkthroughs.


C# Tutorial (by Joe Mayo)
(http://www.csharp-station.com/Tutorial.aspx)
Welcome to the C# Station Tutorial This is a set of lessons suited for beginning to intermediate programmers or anyone who would like to gain familiarity with the C# programming language. These lessons will help you get a quick head-start with C# programming.

Lesson 01: Getting Started
Lesson 02: Expressions, Types, and Variables
Lesson 03: Control Statements – Selection
Lesson 04: Control Statements – Loops
Lesson 05: Methods
Lesson 06: Namespaces
Lesson 07: Introduction to Classes
Lesson 08: Class Inheritance
Lesson 09: Polymorphism
Lesson 10: Properties
Lesson 11: Indexers
Lesson 12: Structs
Lesson 13: Interfaces
Lesson 14: Introduction to Delegates and Events
Lesson 15: Introduction to Exception Handling
Lesson 16: Using Attributes
Lesson 17: Enums
Lesson 18: Overloading Operators
Lesson 19: Encapsulation
Lesson 20: Introduction to Generic Collections
Lesson 21: Anonymous Methods
Lesson 22: Topics on C# Type
Lesson 23: Working with Nullable Types

Download C# Succintly (2015) by Joe Mayo (PDF 1,971KB)


The complete C# Tutorial
(http://csharp.net-tutorials.com/)
Welcome to this C# Tutorial, currently consisting of 49 articles covering all the most important C# concepts. This tutorial is primarily for new users of this great technology, and we recommend you to go through all the chapters, to get the most out of it as possible. While each chapter can be used without reading the previous chapters, some of them may reference things done in earlier chapters.


Classes and Structs (C# Programming Guide)
(https://msdn.microsoft.com/en-us/library/ms173109.aspx)

Classes and structs are two of the basic constructs of the common type system in the .NET Framework. Each is essentially a data structure that encapsulates a set of data and behaviors that belong together as a logical unit. The data and behaviors are the members of the class or struct, and they include its methods, properties, and events, and so on, as listed later in this topic.

A class or struct declaration is like a blueprint that is used to create instances or objects at run time. If you define a class or struct called Person, Person is the name of the type. If you declare and initialize a variable p of type Person, p is said to be an object or instance of Person. Multiple instances of the same Person type can be created, and each instance can have different values in its properties and fields.

A class is a reference type. When an object of the class is created, the variable to which the object is assigned holds only a reference to that memory. When the object reference is assigned to a new variable, the new variable refers to the original object. Changes made through one variable are reflected in the other variable because they both refer to the same data.

A struct is a value type. When a struct is created, the variable to which the struct is assigned holds the struct’s actual data. When the struct is assigned to a new variable, it is copied. The new variable and the original variable therefore contain two separate copies of the same data. Changes made to one copy do not affect the other copy.

In general, classes are used to model more complex behavior, or data that is intended to be modified after a class object is created. Structs are best suited for small data structures that contain primarily data that is not intended to be modified after the struct is created.


Classes (C# Programming Guide)
(https://msdn.microsoft.com/en-GB/library/x9afc042.aspx)

A class is a construct that enables you to create your own custom types by grouping together variables of other types, methods and events. A class is like a blueprint. It defines the data and behavior of a type. If the class is not declared as static, client code can use it by creating objects or instances which are assigned to a variable. The variable remains in memory until all references to it go out of scope. At that time, the CLR marks it as eligible for garbage collection. If the class is declared as static, then only one copy exists in memory and client code can only access it through the class itself, not an instance variable.

Unlike structs, classes support inheritance, a fundamental characteristic of object-oriented programming.


Objects (C# Programming Guide)
(https://msdn.microsoft.com/en-gb/library/ms173110.aspx)
A class or struct definition is like a blueprint that specifies what the type can do. An object is basically a block of memory that has been allocated and configured according to the blueprint. A program may create many objects of the same class. Objects are also called instances, and they can be stored in either a named variable or in an array or collection. Client code is the code that uses these variables to call the methods and access the public properties of the object. In an object-oriented language such as C#, a typical program consists of multiple objects interacting dynamically.


Structs (C# Programming Guide)
(https://msdn.microsoft.com/en-us/library/saxz13w4.aspx)

Structs share most of the same syntax as classes, although structs are more limited than classes:

  • Within a struct declaration, fields cannot be initialized unless they are declared as const or static.
  • A struct cannot declare a default constructor (a constructor without parameters) or a destructor.
  • Structs are copied on assignment. When a struct is assigned to a new variable, all the data is copied, and any modification to the new copy does not change the data for the original copy. This is important to remember when working with collections of value types such as Dictionary<string, myStruct>.
  • Structs are value types and classes are reference types.
  • Unlike classes, structs can be instantiated without using a new operator.
  • Structs can declare constructors that have parameters.
  • A struct cannot inherit from another struct or class, and it cannot be the base of a class. All structs inherit directly from System.ValueType, which inherits from System.Object.
  • A struct can implement interfaces.
  • A struct can be used as a nullable type and can be assigned a null value.

C# Heap(ing) Vs Stack(ing) in .NET: Part I 
(http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory01122006130034PM/csharp_memory.aspx)


C# Heap(ing) Vs Stack(ing) in .NET: Part II
(http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory2B01142006125918PM/csharp_memory2B.aspx)


C# Heap(ing) Vs Stack(ing) in .NET: Part III
(http://jakege.blogspot.co.uk/2013/07/c-heaping-vs-stacking-in-net-part-iii.html)


C# Heap(ing) Vs Stack(ing) in .NET: Part IV
(http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory_401282006141834PM/csharp_memory_4.aspx)


C# Tutorials – Lesson 8: The Members of the Main Class
(http://www.functionx.com/csharp1/Lesson08.htm)
One of the purposes of writing a program is to perform assignments. An assignment can also be called a function. The C# doesn’t have the same notion of a function as did traditional and previous languages like C/C++, Pascal, etc. Instead, in C#, a function must belong to a class. Therefore, in C#, a function is a section whose job is to take care of an operation that would complement a class. Because a function in this case belongs to a particular class, the function is also called a method. From now on, the name method will be used for a function.


C# Tutorials – Lesson 9: Methods and their Parameters
(http://www.functionx.com/csharp1/Lesson09.htm)


C# Tutorials – Lesson 11: The Properties of a Class
(http://www.functionx.com/csharp1/Lesson11.htm)


C# Tutorials – Lesson 10: Introduction to Classes
(http://www.functionx.com/csharp1/Lesson10.htm)


C# Tutorials – Lesson 12: Classes Interactions
(http://www.functionx.com/csharp1/Lesson12.htm)


Six important .NET concepts: Stack, heap, value types, reference types, boxing, and unboxing
(http://www.codeproject.com/Articles/76153/Six-important-NET-concepts-Stack-heap-value-types)
This article will explain six important concepts: stack, heap, value types, reference types, boxing, and unboxing. This article starts explaining what happens internally when you declare a variable and then it moves ahead to explain two important concepts: stack and heap. The article then talks about reference types and value types and clarifies some of the important fundamentals around them.


Stack and Heap – Memory Allocation
(http://www.i-programmer.info/ebooks/deep-c/363)
When you declare a new variable the compiler has to generate code that allocates sufficient memory to store the data it is to hold. The whole subject of memory allocation is a complicated and interesting one but every programmer should know about the two very general approaches – the stack and the heap.


C# Concepts: Value vs Reference Types
(http://www.albahari.com/valuevsreftypes.aspx)
One area likely to cause confusion for those coming from a Java or VB6 background is the distinction between value types and reference types in C#.  In particular, C# provides two types—class and struct, which are almost the same except that one is a reference type while the other is a value type.  This article explores their essential differences, and the practical implications when programming in C#.


How to Program in C# – BASICS – Beginner Tutorial
(https://www.youtube.com/watch?v=pSiIHe2uZ2w)


C# Programming Tutorial – Step by Step
(https://www.youtube.com/watch?v=OBsGRqXzOhk)


C# Fundamentals: Development for Absolute Beginners
(https://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners)


C# Beginners Tutorial -TheNewBoston
(https://www.thenewboston.com/videos.php?cat=15)


A C# Crash Course
(http://rbwhitaker.wikidot.com/c-sharp-tutorials)


C# Tutorial for Beginners
(http://www.c-sharpcorner.com/beginners/)


Free Udemy Video Tutorial – Intro C#
(https://www.udemy.com/intro-c-sharp/)


Free Udemy Video Tutorial – Introduction to C# – Getting Started
(https://www.udemy.com/intro-2-csharp/)


An Advanced Introduction to C# – Lecture Notes Part 1 of 4
(http://www.codeproject.com/Articles/1094079/An-advanced-introduction-to-Csharp-Lecture-Notes-P#the-right-development-environment)

In the first part we introduce the basic concepts of C# along with object oriented programming and the .NET-Framework.

  1. Introduction
  2. The right development environment
  3. Basic concepts
  4. Namespaces
  5. Data types and operators
  6. Reference and value types
  7. Control flow
  8. Object-oriented programming
  9. Inheritance and polymorphism
  10. Access modifiers
  11. Properties
  12. The constructor
  13. Abstract classes and interfaces
  14. Exception handling
  15. Outlook
  16. Other Articles in this Series
  17. References
  18. History

This tutorial aims to give a brief and advanced introduction into programming with C#. The prerequisites for understanding this tutorial are a working knowledge of programming, the C programming language and a little bit of basic mathematics. Some basic knowledge of C++ or Java could be helpful, but should not be required.

Introduction

This is the first part of a series of tutorials on C#. In this part we are introducing the fundamental concepts of the language and it’s output, the Microsoft Intermediate Language (MSIL). We will take a look at object-oriented programming (OOP) and what C# does to make OOP as efficient as possible to realize in practice.

For further reading a list of references will be given in the end. The references provide a deeper look at some of the topics discussed in this tutorial.

A little bit of warning before reading this tutorial: The way that this tutorial works is that it defines a path of usability. This part of the tutorial is essentially required before doing anything with C#. After this first tutorial everyone should be able to write a simple C# program using basic object-oriented principles. Hence more advanced or curious readers will probably miss some parts. As an example we will not investigate exception handling, exciting possibilities with the .NET-Framework like LINQ and more advanced language features like generics or lambda expressions. Here our aim is to give a soft introduction to C# for people coming from other languages.

Other Articles in this Series

  1. Lecture Notes Part 1 of 4 – An advanced introduction to C#
  2. Lecture Notes Part 2 of 4 – Mastering C#
  3. Lecture Notes Part 3 of 4 – Advanced programming with C#
  4. Lecture Notes Part 4 of 4 – Professional techniques for C#

References