SlideShare a Scribd company logo
Introduction to C#




            FCIS
Summer training 2010, 1st year.

       Mohamed Samy
Aims of this course
 
     This course is an introduction to:
     
         The Event-driven programming model
     
         Writing GUI applications
     
         Object oriented programming
     
         The C# language
 
     While learning, these resources will help you:
     
         The lecture
     
         The labs
     
         The C# reference, released in parts
     
         ...but you need to practice, or all this will be
         worthless
             
                 Seriously :(
Tools
 
     This course uses Visual C# Express edition
     (which is a free download from Microsoft)
        −   http://www.microsoft.com/express/Windows/
New ideas about programming...

 
     Event-driven programming
 
     Object oriented programming
     
         Better for modeling
     
         Objects have state and behavior (attributes and
         methods).
     
         Classes, subclasses.
     
         Interface vs. implementation.
Event-driven programming

 Normal program       Event-driven program
 main( )              main( )
 {                    {
     doSubtask1( );       on event1 do { … }
     doSubtask2( );       on event2 do { … }
     doSubtask3( );       on event 3 do { … }
                          waitForEvents( );
 }
                      }
Event-driven programming

 Examples of events:
 
     Keyboard and mouse actions.
 
     Typing in a text box.
 
     Renaming a file.
 
     Arrival of data from the network.
 
     Adding an item to a collection.
 
     ...
OOP – Modeling the problem
 
     A word processor can use objects to represent:
        −   Paragraphs and pages
        −   Toolbars and dialogs
        −   Graphical objects
OOP – Modeling the problem
 
     A strategy game can use objects to represent:
        −   Units and buildings
        −   Teams
        −   Strategies and algorithms
OOP – Modeling the problem
 
     A desktop operating system can use objects
     to represent:
       −   Files and folders
       −   Hardware devices
What's an Object?

 
     An object has state and behavior.
 
     It represents state via attributes and behavior
     via methods.
 
     It has an interface and an internal
     implementation. Separating the interface from
     the implementation is encapsulation.
 
     Multiple object types can have the same
     interface, thus opening the door for
     polymorphism.
Objects and classes

    Classes describe the common attributes and
    behavior of related objects.

    You can do OOP without classes, but most
    OOP languages have them.

    A C# class has fields (data members, member
    variables) and methods (member functions).

    Fields and methods can be static or non-
    static.
       −   Non-static methods are also called instance methods or
           object methods. Same for fields.

    Classes can be superclasses or subclasses.
    Superclasses provide abstraction over types.
Let's do some programming

 
     "X owns Y" program
 
     The bouncing head program
What can be done with objects?

 
     Creating new objects
 
     Reading and writing fields
 
     Reading and writing properties
 
     Calling methods.
GUI without the designer
 using System.Windows.Forms;
 class Program
 {
     static void Main()
     {
         Form f;
         f = new Form();
         f.Text = "A simple program";
         f.SetBounds(20, 20, 400, 400);
         Application.Run(f); // for the main form only!!
     }
 }
Namespaces

    C# (actually, .net) program elements are
    organized into namespaces.

    To access an element in another namesoace,
    either use its full name nsName.elementName
    or import all the names from the namespace
    with using ...;

    To define your own namespaces, you can do
    this:
    
        namespace MyNS
    {
        class ABC { ... }
        class DEF { … }
    }
Instantiation

    The declaration
    Form f;
Tells the compiler the type of ' f ', but it does not
 create a new object.

    The only way to create an object is with new
    f = new Form( );

    New does 3 things
        −   Allocate memory for the object
        −   Initialize the object
        −   Return a reference to the object as the value of the new
            expression.
    
        Note: A reference is a number that's used to access
        an object. It's similar (but not the same) to pointers.
Setting properties

    The statement
   f.Text = "A simple program";
is the setting of a property (properties looks like
  member variables, but act like functions).

    You can also set member variables with the same
    syntax. Member variables work mostly like C++'s
    structs.
Setting properties / calling methods

    The statement
   f.SetBounds(20, 20, 400, 400);
Is a method call. In this case SetBounds is an
  instance method since it needs an object reference
  ' f ' to be called.

    The statement
   Application.Run(f);
Is calling the static method Run defined in the class
  Application. It is a static method since it doesn't
  need an object reference; but only a class name.
Terminology

           Related names                       Element

Instance                                        Object

Data member, Member variable,
                                                 Field
attribute

Member function                                 Method

Class method                                 Static method

Instance method, object method.            Non-static method

 Note
 While the names are conceptually related, they do not necessarily
 have the exact same meaning.
Next time...

 
     Reference types, Arrays, foreach...
 
     Graphics
 
     Handling KB events

 
     Remember to download the reference!

More Related Content

PDF
C# Summer course - Lecture 2
PDF
Implementation of oop concept in c++
PDF
C++ [ principles of object oriented programming ]
PPT
20. Object-Oriented Programming Fundamental Principles
PPTX
Object oriented programming Fundamental Concepts
PPTX
Learn Concept of Class and Object in C# Part 3
PPTX
Programming Fundamentals With OOPs Concepts (Java Examples Based)
C# Summer course - Lecture 2
Implementation of oop concept in c++
C++ [ principles of object oriented programming ]
20. Object-Oriented Programming Fundamental Principles
Object oriented programming Fundamental Concepts
Learn Concept of Class and Object in C# Part 3
Programming Fundamentals With OOPs Concepts (Java Examples Based)

What's hot (20)

PPTX
Introduction to oop
PDF
Object oriented programming With C#
PDF
Object-oriented Programming-with C#
PPT
Oops And C++ Fundamentals
PPTX
Oop in c++ lecture 1
PPT
Introduction to oop
PPT
Concepts In Object Oriented Programming Languages
PPTX
SKILLWISE - OOPS CONCEPT
PPTX
Oop c++class(final).ppt
PPTX
C++ Object Oriented Programming
PDF
Object Oriented Programming using C++ Part I
PPTX
Lecture 1 uml with java implementation
PDF
Reviewing OOP Design patterns
PPTX
Object Oriented Technologies
PPTX
OOP Unit 2 - Classes and Object
PPT
Oops ppt
PPTX
Object Oriented Programming with C#
PDF
Object-oriented programming (OOP) with Complete understanding modules
PPT
Inheritance : Extending Classes
PPTX
2CPP14 - Abstraction
Introduction to oop
Object oriented programming With C#
Object-oriented Programming-with C#
Oops And C++ Fundamentals
Oop in c++ lecture 1
Introduction to oop
Concepts In Object Oriented Programming Languages
SKILLWISE - OOPS CONCEPT
Oop c++class(final).ppt
C++ Object Oriented Programming
Object Oriented Programming using C++ Part I
Lecture 1 uml with java implementation
Reviewing OOP Design patterns
Object Oriented Technologies
OOP Unit 2 - Classes and Object
Oops ppt
Object Oriented Programming with C#
Object-oriented programming (OOP) with Complete understanding modules
Inheritance : Extending Classes
2CPP14 - Abstraction
Ad

Viewers also liked (20)

PPT
Visula C# Programming Lecture 2
PPT
C# basics
PPTX
.NET and C# Introduction
PPT
Introduction To Dotnet
PPT
Csc153 chapter 07
 
PPT
Csc153 chapter 04
 
PPT
Csc253 chapter 09
 
PPT
Visula C# Programming Lecture 6
PPT
Csc153 chapter 02
 
PPT
Visula C# Programming Lecture 1
PPT
Csc153 chapter 01
 
PPTX
.NET and C# introduction
PPTX
CSharp Presentation
PPT
C#.NET
PPSX
Microsoft C# programming basics
PPTX
Introduction to .NET Programming
PPT
Introduction to .NET Framework
PPT
.NET Framework Overview
PPT
Architecture of .net framework
Visula C# Programming Lecture 2
C# basics
.NET and C# Introduction
Introduction To Dotnet
Csc153 chapter 07
 
Csc153 chapter 04
 
Csc253 chapter 09
 
Visula C# Programming Lecture 6
Csc153 chapter 02
 
Visula C# Programming Lecture 1
Csc153 chapter 01
 
.NET and C# introduction
CSharp Presentation
C#.NET
Microsoft C# programming basics
Introduction to .NET Programming
Introduction to .NET Framework
.NET Framework Overview
Architecture of .net framework
Ad

Similar to C# Summer course - Lecture 1 (20)

PPT
Object Oriented Programming In .Net
PDF
conceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdf
PPT
Oop java
PPT
Chapter 1- Introduction.ppt
PPT
PPTX
iOS development introduction
PPT
ActionScript 3.0 Fundamentals
PPTX
1 intro
PPTX
Java notes jkuat it
PPTX
Java notes(OOP) jkuat IT esection
PPT
Java Script Patterns
PPTX
CPP_,module2_1.pptx
PPT
The Larch - a visual interactive programming environment
PPTX
java oops and java very important for .pptx
PPTX
java oops compilation object class inheritance.pptx
PPT
the education purpose of software C++.ppt
PPTX
Chapter1 introduction
PPTX
Introduction to Design Patterns
PPT
iOS Application Development
PPTX
Interoduction to c++
Object Oriented Programming In .Net
conceptsinobjectorientedprogramminglanguages-12659959597745-phpapp02.pdf
Oop java
Chapter 1- Introduction.ppt
iOS development introduction
ActionScript 3.0 Fundamentals
1 intro
Java notes jkuat it
Java notes(OOP) jkuat IT esection
Java Script Patterns
CPP_,module2_1.pptx
The Larch - a visual interactive programming environment
java oops and java very important for .pptx
java oops compilation object class inheritance.pptx
the education purpose of software C++.ppt
Chapter1 introduction
Introduction to Design Patterns
iOS Application Development
Interoduction to c++

More from mohamedsamyali (10)

PDF
Computational thinking in Egypt
PDF
C++ syntax summary
PDF
C# Summer course - Lecture 3
PDF
C# Summer course - Lecture 4
PDF
Computer science department - a four page presentation
PDF
Presentation skills for Graduation projects
PDF
Erlang session1
PDF
Erlang session2
PDF
Themes for graduation projects 2010
PDF
Smalltalk, the dynamic language
Computational thinking in Egypt
C++ syntax summary
C# Summer course - Lecture 3
C# Summer course - Lecture 4
Computer science department - a four page presentation
Presentation skills for Graduation projects
Erlang session1
Erlang session2
Themes for graduation projects 2010
Smalltalk, the dynamic language

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
cuic standard and advanced reporting.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Spectroscopy.pptx food analysis technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
MYSQL Presentation for SQL database connectivity
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Unlocking AI with Model Context Protocol (MCP)
cuic standard and advanced reporting.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Programs and apps: productivity, graphics, security and other tools
20250228 LYD VKU AI Blended-Learning.pptx
The AUB Centre for AI in Media Proposal.docx
Spectroscopy.pptx food analysis technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
MYSQL Presentation for SQL database connectivity

C# Summer course - Lecture 1

  • 1. Introduction to C# FCIS Summer training 2010, 1st year. Mohamed Samy
  • 2. Aims of this course  This course is an introduction to:  The Event-driven programming model  Writing GUI applications  Object oriented programming  The C# language  While learning, these resources will help you:  The lecture  The labs  The C# reference, released in parts  ...but you need to practice, or all this will be worthless  Seriously :(
  • 3. Tools  This course uses Visual C# Express edition (which is a free download from Microsoft) − http://www.microsoft.com/express/Windows/
  • 4. New ideas about programming...  Event-driven programming  Object oriented programming  Better for modeling  Objects have state and behavior (attributes and methods).  Classes, subclasses.  Interface vs. implementation.
  • 5. Event-driven programming Normal program Event-driven program main( ) main( ) { { doSubtask1( ); on event1 do { … } doSubtask2( ); on event2 do { … } doSubtask3( ); on event 3 do { … } waitForEvents( ); } }
  • 6. Event-driven programming Examples of events:  Keyboard and mouse actions.  Typing in a text box.  Renaming a file.  Arrival of data from the network.  Adding an item to a collection.  ...
  • 7. OOP – Modeling the problem  A word processor can use objects to represent: − Paragraphs and pages − Toolbars and dialogs − Graphical objects
  • 8. OOP – Modeling the problem  A strategy game can use objects to represent: − Units and buildings − Teams − Strategies and algorithms
  • 9. OOP – Modeling the problem  A desktop operating system can use objects to represent: − Files and folders − Hardware devices
  • 10. What's an Object?  An object has state and behavior.  It represents state via attributes and behavior via methods.  It has an interface and an internal implementation. Separating the interface from the implementation is encapsulation.  Multiple object types can have the same interface, thus opening the door for polymorphism.
  • 11. Objects and classes  Classes describe the common attributes and behavior of related objects.  You can do OOP without classes, but most OOP languages have them.  A C# class has fields (data members, member variables) and methods (member functions).  Fields and methods can be static or non- static. − Non-static methods are also called instance methods or object methods. Same for fields.  Classes can be superclasses or subclasses. Superclasses provide abstraction over types.
  • 12. Let's do some programming  "X owns Y" program  The bouncing head program
  • 13. What can be done with objects?  Creating new objects  Reading and writing fields  Reading and writing properties  Calling methods.
  • 14. GUI without the designer using System.Windows.Forms; class Program { static void Main() { Form f; f = new Form(); f.Text = "A simple program"; f.SetBounds(20, 20, 400, 400); Application.Run(f); // for the main form only!! } }
  • 15. Namespaces  C# (actually, .net) program elements are organized into namespaces.  To access an element in another namesoace, either use its full name nsName.elementName or import all the names from the namespace with using ...;  To define your own namespaces, you can do this:  namespace MyNS { class ABC { ... } class DEF { … } }
  • 16. Instantiation  The declaration Form f; Tells the compiler the type of ' f ', but it does not create a new object.  The only way to create an object is with new f = new Form( );  New does 3 things − Allocate memory for the object − Initialize the object − Return a reference to the object as the value of the new expression.  Note: A reference is a number that's used to access an object. It's similar (but not the same) to pointers.
  • 17. Setting properties  The statement f.Text = "A simple program"; is the setting of a property (properties looks like member variables, but act like functions).  You can also set member variables with the same syntax. Member variables work mostly like C++'s structs.
  • 18. Setting properties / calling methods  The statement f.SetBounds(20, 20, 400, 400); Is a method call. In this case SetBounds is an instance method since it needs an object reference ' f ' to be called.  The statement Application.Run(f); Is calling the static method Run defined in the class Application. It is a static method since it doesn't need an object reference; but only a class name.
  • 19. Terminology Related names Element Instance Object Data member, Member variable, Field attribute Member function Method Class method Static method Instance method, object method. Non-static method Note While the names are conceptually related, they do not necessarily have the exact same meaning.
  • 20. Next time...  Reference types, Arrays, foreach...  Graphics  Handling KB events  Remember to download the reference!