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

What's hot (20)

PPTX
Introduction to oop
colleges
 
PDF
Object oriented programming With C#
Youssef Mohammed Abohaty
 
PDF
Object-oriented Programming-with C#
Doncho Minkov
 
PPT
Oops And C++ Fundamentals
Subhasis Nayak
 
PPTX
Oop in c++ lecture 1
zk75977
 
PPT
Introduction to oop
Kumar
 
PPT
Concepts In Object Oriented Programming Languages
ppd1961
 
PPTX
SKILLWISE - OOPS CONCEPT
Skillwise Group
 
PPTX
Oop c++class(final).ppt
Alok Kumar
 
PPTX
C++ Object Oriented Programming
Gamindu Udayanga
 
PDF
Object Oriented Programming using C++ Part I
Ajit Nayak
 
PPTX
Lecture 1 uml with java implementation
the_wumberlog
 
PDF
Reviewing OOP Design patterns
Olivier Bacs
 
PPTX
Object Oriented Technologies
Tushar B Kute
 
PPTX
OOP Unit 2 - Classes and Object
dkpawar
 
PPT
Oops ppt
abhayjuneja
 
PPTX
Object Oriented Programming with C#
foreverredpb
 
PDF
Object-oriented programming (OOP) with Complete understanding modules
Durgesh Singh
 
PPT
Inheritance : Extending Classes
Nilesh Dalvi
 
PPTX
2CPP14 - Abstraction
Michael Heron
 
Introduction to oop
colleges
 
Object oriented programming With C#
Youssef Mohammed Abohaty
 
Object-oriented Programming-with C#
Doncho Minkov
 
Oops And C++ Fundamentals
Subhasis Nayak
 
Oop in c++ lecture 1
zk75977
 
Introduction to oop
Kumar
 
Concepts In Object Oriented Programming Languages
ppd1961
 
SKILLWISE - OOPS CONCEPT
Skillwise Group
 
Oop c++class(final).ppt
Alok Kumar
 
C++ Object Oriented Programming
Gamindu Udayanga
 
Object Oriented Programming using C++ Part I
Ajit Nayak
 
Lecture 1 uml with java implementation
the_wumberlog
 
Reviewing OOP Design patterns
Olivier Bacs
 
Object Oriented Technologies
Tushar B Kute
 
OOP Unit 2 - Classes and Object
dkpawar
 
Oops ppt
abhayjuneja
 
Object Oriented Programming with C#
foreverredpb
 
Object-oriented programming (OOP) with Complete understanding modules
Durgesh Singh
 
Inheritance : Extending Classes
Nilesh Dalvi
 
2CPP14 - Abstraction
Michael Heron
 

Viewers also liked (20)

PPT
Visula C# Programming Lecture 2
Abou Bakr Ashraf
 
PPT
C# basics
Dinesh kumar
 
PPTX
.NET and C# Introduction
Siraj Memon
 
PPT
Introduction To Dotnet
SAMIR BHOGAYTA
 
PPT
Csc153 chapter 07
PCC
 
PPT
Csc153 chapter 04
PCC
 
PPT
Csc253 chapter 09
PCC
 
PPT
Visula C# Programming Lecture 6
Abou Bakr Ashraf
 
PPT
Csc153 chapter 02
PCC
 
PPT
Visula C# Programming Lecture 1
Abou Bakr Ashraf
 
PPT
Csc153 chapter 01
PCC
 
PPTX
.NET and C# introduction
Peter Gfader
 
PPTX
CSharp Presentation
Vishwa Mohan
 
PPT
C#.NET
gurchet
 
PPSX
Microsoft C# programming basics
Prognoz Technologies Pvt. Ltd.
 
PPTX
Introduction to .NET Programming
Karthikeyan Mkr
 
PPT
Introduction to .NET Framework
Raghuveer Guthikonda
 
PPT
.NET Framework Overview
Doncho Minkov
 
PPT
Architecture of .net framework
Then Murugeshwari
 
Visula C# Programming Lecture 2
Abou Bakr Ashraf
 
C# basics
Dinesh kumar
 
.NET and C# Introduction
Siraj Memon
 
Introduction To Dotnet
SAMIR BHOGAYTA
 
Csc153 chapter 07
PCC
 
Csc153 chapter 04
PCC
 
Csc253 chapter 09
PCC
 
Visula C# Programming Lecture 6
Abou Bakr Ashraf
 
Csc153 chapter 02
PCC
 
Visula C# Programming Lecture 1
Abou Bakr Ashraf
 
Csc153 chapter 01
PCC
 
.NET and C# introduction
Peter Gfader
 
CSharp Presentation
Vishwa Mohan
 
C#.NET
gurchet
 
Microsoft C# programming basics
Prognoz Technologies Pvt. Ltd.
 
Introduction to .NET Programming
Karthikeyan Mkr
 
Introduction to .NET Framework
Raghuveer Guthikonda
 
.NET Framework Overview
Doncho Minkov
 
Architecture of .net framework
Then Murugeshwari
 
Ad

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

PPT
03 oo with-c-sharp
Naved khan
 
PDF
Oop c sharp_part_1
shivaksn
 
PPTX
C#
Gokul Ram
 
DOC
C# by Zaheer Abbas Aghani
Information Technology Center
 
DOC
C# by Zaheer Abbas Aghani
Information Technology Center
 
PPT
Introduction to csharp
hmanjarawala
 
PPT
Introduction to csharp
voegtu
 
PPT
Introduction to csharp
voegtu
 
PPT
Object Oriented Programming In .Net
Greg Sohl
 
PPT
Week1
Uzma Qureshi
 
PDF
[Ebooks PDF] download C How to Program 1ST Edition Harvey M. Deitel full chap...
raaenvalko0u
 
PDF
Introduction to c#
singhadarsh
 
PDF
Introduction To Csharp
sarfarazali
 
DOC
10266 developing data access solutions with microsoft visual studio 2010
bestip
 
PPT
Ooad ch 2
anujabeatrice2
 
PPT
Visual programming lecture
AqsaHayat3
 
DOC
Csharp
vinayabburi
 
PDF
1204csharp
g_hemanth17
 
PPT
ActionScript 3.0 Fundamentals
Saurabh Narula
 
PPT
Using class and object java
mha4
 
03 oo with-c-sharp
Naved khan
 
Oop c sharp_part_1
shivaksn
 
C# by Zaheer Abbas Aghani
Information Technology Center
 
C# by Zaheer Abbas Aghani
Information Technology Center
 
Introduction to csharp
hmanjarawala
 
Introduction to csharp
voegtu
 
Introduction to csharp
voegtu
 
Object Oriented Programming In .Net
Greg Sohl
 
[Ebooks PDF] download C How to Program 1ST Edition Harvey M. Deitel full chap...
raaenvalko0u
 
Introduction to c#
singhadarsh
 
Introduction To Csharp
sarfarazali
 
10266 developing data access solutions with microsoft visual studio 2010
bestip
 
Ooad ch 2
anujabeatrice2
 
Visual programming lecture
AqsaHayat3
 
Csharp
vinayabburi
 
1204csharp
g_hemanth17
 
ActionScript 3.0 Fundamentals
Saurabh Narula
 
Using class and object java
mha4
 
Ad

More from mohamedsamyali (10)

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

Recently uploaded (20)

PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 

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!