Notes
Slide Show
Outline
1
Introduction to C#
  • Andrew Scott
    Computing Department
    Lancaster University, UK
2
C# Keywords
3
Last week… creating exceptions
4
Overloading Method Names
5
Namespaces
6
Namespaces and Using
7
Namespaces and Using
8
Interfaces
  • Abstract definition of an object ‘characteristic’


  • Includes abstract definition of
    • Indexers
    • Methods
    • Properties

  • Names should start with an I
    • IComparable

9
Classes and Interfaces
  • Classes implement one or more Interfaces
    • Multiple inheritance

  • Classes can extend only one base class
    • Single inheritance
10
Interfaces v Classes
  • Interface
    • General characteristic: Printable

  • Abstract Class
    • Limited grouping: Processor

  • Class
    • Specific implementation: Intel Pentium III
11
Polymorphism
12
Polymorphism
13
…and for classes
14
…and for classes
15
Preventing Inheritance
  • sealed
    • Prevents classes inheriting from a class
16
Collections
  • Implement IEnumerable
    • IEnumerator GetEnumerator()
    • For example, System.Array class

  • Iterator: foreach(type var in ICollection)
17
Collection Classes
18
Collection Classes
19
Arrays
20
Structs
  • No inheritance


  • Passed by value
    • Class based objects passed by reference

  • Value type and always they have value
    • Cannot be null, unlike class based objects

  • Can have methods and properties
    • Cannot have a finalize method
21
Enumerators
22
Enumerators
23
Access Rights
  • Public: Not restricted


  • Protected: Containing class or types derived from it


  • Internal: Current project/assembly


  • Protected internal:
    • Current project/assembly
    • Containing class or types derived from it


  • Private: Containing type
24
Access to Members of Types
  • Class   [private, by default]
    • Public, protected, internal, protected internal, private

  • Enum   [public]


  • Interface   [public]


  • Struct   [private]
    • Public, internal, private
25
C# Keywords