Teaching with C Sharp Rob Miles.

Slides:



Advertisements
Similar presentations
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++
Advertisements

Introduction to the C# Programming Language for the VB Programmer.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Tahir Nawaz Visual Programming C# Week 2. What is C#? C# (pronounced "C sharp") is an object- oriented language that is used to build applications for.
Object Oriented Software Development 1. Introduction to C# and Visual Studio.
From C++ to C#. Web programming The course is on web programming using ASP.Net and C# The course is on web programming using ASP.Net and C# ASP.Net is.
A Free sample background from © 2001 By Default!Slide 1.NET Overview BY: Pinkesh Desai.
Starting Chapter 4 Starting. 1 Course Outline* Covered in first half until Dr. Li takes over. JAVA and OO: Review what is Object Oriented Programming.
M1G Introduction to Programming 2 4. Enhancing a class:Room.
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Computing IV Visual C Introduction with OpenCV Example Xinwen Fu.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
Lecture 1 Programming in C# Introducing C# Writing a C# Program.
11 A First Game Program Session Session Overview  Begin the creation of an arcade game  Learn software design techniques that apply to any form.
Lecture Set 2 Part B – Configuring Visual Studio; Configuration Options and The Help System (scan quickly for future reference)
May 9, 2002Serguei A. Mokhov, 1 Kickstart Intro to Java Part I COMP346/ Operating Systems Revision 1.6 February 9, 2004.
Teaching with C Sharp Rob Miles. Overview  Introduction >My perspective  C# and Java >Broad overview of the languages  Significant C# Features >C#
Object Oriented Software Development
Getting Started with.NET Getting Started with.NET/Lesson 1/Slide 1 of 31 Objectives In this lesson, you will learn to: *Identify the components of the.NET.
04 |Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio Ben Riga
Visual Programming Borland Delphi. Developing Applications Borland Delphi is an object-oriented, visual programming environment to develop 32-bit applications.
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
JavaScript/ App Lab Programming:
Advanced Computer Systems
C# for C++ Programmers 1.
INF230 Basics in C# Programming
Component and Deployment Diagrams
Objects First with Java A Practical Introduction using BlueJ
Abstract Data Types and Encapsulation Concepts
Templates.
Classes and OOP.
Object-Oriented Analysis and Design
Java Programming Language
CSC 221: Computer Programming I Fall 2005
Java Beans Sagun Dhakhwa.
R For The SQL Developer Kevin Feasel Manager, Predictive Analytics
Introduction to .NET Framework Ch2 – Deitel’s Book
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Creating and Modifying Text part 2
CS360 Windows Programming
Module 1: Getting Started
Introduction to C# AKEEL AHMED.
Tutorial C#.
C# In many ways, C# looks similar to Java
Lecturer: Mukhtar Mohamed Ali “Hakaale”
VISUAL BASIC.
Objects First with Java
Chapter 10 Thinking in Objects
Abstract Data Types and Encapsulation Concepts
Introduction to Data Structures
Java Programming Language
MSIS 655 Advanced Business Applications Programming
Object Oriented Practices
Chapter 7 –Implementation Issues
CISC124 Assignment 4 on Inheritance due next Friday.
Tonga Institute of Higher Education
Objects First with Java A Practical Introduction using BlueJ
Creating Computer Programs
(Computer fundamental Lab)
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Java Programming Language
Objects First with Java A Practical Introduction using BlueJ
Chap 1. Getting Started Objectives
Creating Computer Programs
CMSC 202 Exceptions.
SPL – PS1 Introduction to C++.
IS 135 Business Programming
From Use Cases to Implementation
Presentation transcript:

Teaching with C Sharp Rob Miles

Overview Introduction C# and Java Significant C# Features Conclusion My perspective C# and Java Broad overview of the languages Significant C# Features C# features from a teaching perspective Conclusion ..and possibly a sing song?

Introduction The material is based on my experience teaching C# to two student cohorts It is necessarily coloured by my teaching philosophy It has been presented in targeted sections so that you can use those components which suit your purpose There are number of sample projects for each section which form the basis of the lab work

Presentation Notes A full set of notes is provided for this presentation The notes are broken down in the same sequence as the items given here Each section is followed by a number of practical examples along with some ideas for investigation

Bonus Materials As this is the “collectors edition” of the course Just like every other edition… It is supplied with bonus materials in the form of a copy of “C# from Java” This provides an FAQ for a number of conversion issues

Teaching Philosophy At Hull we teach an “algorithms first” course This concentrates on program construction in semester one and introduces objects in semester two Everything is placed in the strongest possible “real world” context and I make heavy use of analogies

Objects Objects are presented as a solution to structure and design I try to make a logical transition from structures to components: Encapsulation Business Objects Test driven development Component based design Hierarchies for code reuse

Teaching and C# I have found that C# matches with our teaching philosophy It would also match with an objects first approach, at least as well as Java does The points made later are applicable to both teaching approaches

C# and Java C# is heavily based on Java Conversion from C# to Java (or back) is not difficult C# programs seem to run faster on the PC platform C# is not being positioned as Microsoft proprietary But the language development is Microsoft driven, in the same way that Java development is Sun driven

C# Versions There are now two versions of C# Version 2 adds a number of features: Partial classes Generics There are few breaking changes moving from C# Version 1 to Version 2 This presentation is Version 1 compliant

Development Tools A command line compiler kit is available Directly analogous to the JDK Visual Studio 2005 is available under the Academic Alliance Visual Studio 2005 Express Edition is available for free David will give more details of these later

C# Language Features We can consider some specific C# features: User input/Output Value Types and Structures Exception Handling Reference Parameters Event Handling/Delegates Program Linking and Deployment Properties Generics They will be placed into a teaching context

User input/output The System.Console object provides a range of input/output actions There is no need to create a stream object There is also no need to trap exceptions

demo Simple Input/Output Console Power Text Read and Write and colour manipulation Console Power Moving dot game Use example 01 to read and write a couple of strings and show the text formatting/colour Use example 02 to show the console text positioning etc

Value Types In Java a type is either primitive or reference: Primitive Managed by value Primitive types do not support methods or properties Reference Managed by reference Support methods and properties Slower to manipulate A good description of generics here: http://www.codeproject.com/csharp/Generics_Explained.asp

Java Primitive Problems For a student learning to program the primitive-reference distinction is hard to grasp It also brings a need to describe the use of wrapper classes Students do not like to have to learn the difference between int and Integer This knowledge is not that relevant to other languages

C# value types C# uses a different approach: All types are objects Some types are “value” types, i.e. manipulated by value not reference But they all support methods and properties The “box” operation performs conversion from value to reference as required The C# student need not be aware of any distinction at the start of the course

demo Value type behaviour in .NET 1.1 and .NET 2.0 Using ildasm to look at the IL Show the simple assignment demo. If there is time you can also use ildasm to look at the code

Boxing in Action static void Main(string[] args) { int a, b; a = 99; Console.WriteLine("a is {0} b is {1}", a, b); }

Boxing Assembler

Structures as value types C# supports a struct type This type is directly analogous to the struct in C A struct is manipulated as a value type This allows data to be grouped together without a need to cover objects and references It also allows for more complex exercises

C# Structs A struct in C# is managed by value. However, they do behave a lot like objects They can support methods and properties They can have constructors They can even implement an interface But they do not support inheritance

demo Structures in C# Simple structures Structure “housekeeping” Arrays of structures Show the structures

Exception Handling In Java you have to handle some exceptions (the checked ones) These are thrown by lots of library methods, including input/output In C# all exceptions are unchecked If you don’t catch them the run time system will pick them up This makes things like simple input/output much simpler

demo Exceptions in C# Simple exception handling Creating your own exceptions Show simple exception handling

Reference Parameters Unlike Java, where parameters are always passed by value, in C# reference parameters are allowed This makes programming more efficient It also allows discussion of the meaning of references without the need to consider objects

demo Reference Parameters ref parameters in parameters Show the structures

Event handling and delegates C# provides a delegate type which can be used to create a typesafe reference to a method in an instance of a class There is no need to create an instance of a class to receive events Delegates are used to manage system events and the user interface

demo Event handling with delegates Simple form creation and event management Using the Visual Studio 2005 Forms Designer Show the structures

Delegates and Design Delegates bring function pointers back into programming However, they can be deployed in a typesafe manner in a properly managed environment However, he biggest advantage over Java is that they make interacting with Forms components much easier

Program Linking and Deployment In Java a program is built at run time The classpath is used to locate the required components as the program runs There is little attention paid at build time to linking issues In C# the .exe file is an assembly which may make use of .dll library files There is a distinct difference between an executable file and a library one An exe file will refer to a specific version of a dll when it is built

C# Programs Only one class in a C# program may contain a Main method to provide the entry point During the build process the particular libraries to be used must be specifically identified and located If you are using Visual Studio the metadata from the assembly can be used in interactive help

C# Linking and Teaching I place great emphasis on Business Objects and Test Driven Development The C# linking process fits well with this approach The students are initially introduced to the process by means of compiler directives Later they move on to use Visual Studio 2005

demo Using Business Objects Single workspace containing a number of Visual Studio Projects Show the structures

The naming of components Java provides a package mechanism by which a system can be broken down into components this is linked to the physical position of the file in a directory hierarchy only one public class can placed in each file, and the filename must match the class name C# does not do this A class is placed in a “namespace” which is not physically mapped to storage

C# Namespace Namespaces are hierarchical A single source file can contain components from a number of namespaces A namespace can span multiple source files Visual Studio 2005 provides a view of all the components in a namespace

Partial Classes These are available in C# Version 2.0 A class can be made to span a number of source files This allows the developer to partition the behaviours of a class into a number of separate source files Hide the scary bits? Visual Studio 2005 does this with forms

demo Using Business Objects and Namespaces Advanced multi-project workspace with business and control objects Show the structures

Properties Properties are “syntactic sugar” They provide a convenient wrapper for get and set behaviour in objects There is no need to use them But all of the system library classes do They are best explained in the context of “making life easier”

demo Simple Properties A book title class which uses properties to manage the name of the book Show the structures

Properties and Assembler

Generics Generics are new in Version 2.0 They let you create classes which work on classes You don’t have to give the types of the classes when you write the code Instead you use placeholders which are “filled in” at runtime in a typesafe manner

Generics and teaching I would not teach about generics in the first part of a programming course The fact that they are now present in C# means that we can use this language in later years

Generic Collections The major advantage that generics brings for learner programmers is a better way to deploy collection classes They remove the need to cast items read from the collection Although I must admit I think that covering casting at this point is a good idea

demo Using the List collection class A typesafe list collection is created using the new System.Generics.List collection class Show the structures

Using Generics Generics do make it possible to talk about data structures without dwelling on the type of the data being manipulated This can be rolled into discussions about generalisation which can take place in the latter parts of a first year course

demo Creating and using a generic linked list class A linked list generic which is deployed for both integers and string types Show the structures

Conclusion Students like C# We have seen improved performance in both coursework and examinations It is a more productive programming environment than Java All of the language changes are soundly pragmatic The toolset is very effective and now handles important issues like test driven development C# will do very nicely. For now……

Questions I can take any quick questions now For more detailed ones please catch me in the break or during the labs