Your SlideShare is downloading. ×
0
Class and Method           Programming in C#              tnngo2@gmail.com
Class and Objects
Object-oriented programming      Programming languages designed based on data and ways to      manipulate data.      Proce...
Features      Abstraction      Encapsulation      Inheritance      Polymorphism                      Focus only the requir...
Features      Abstraction      Encapsulation      Inheritance      Polymorphism                      Hide details of what ...
Features      Abstraction      Encapsulation      Inheritance      Polymorphism                      Create a new class ba...
Features      Abstraction      Encapsulation      Inheritance      Polymorphism                      Behave differently in...
Class
Class – should & cannot      Should               be a noun               first letter capitalized               simple, d...
Methods
Method – can & cannot     Can           begin with a letter, _ or @     Cannot           C# keyword           contain spac...
Invoking methods      https://gist.github.com/2349623
Static methods      called without creating any objects of the class      refer only to static variables and other static ...
Static methods      Only one copy of static variable is shared by all the objects of the      class.
Question?     https://gist.github.com/2349708
Access Modifiers
Access Modifiers
Ref      causes arguments to be passed in a method by reference      https://gist.github.com/2344456
Out      similar to ref but no                          required the variables that are passed by      reference to be ini...
Method overloading
Method overloading      every method has a signature which comprises              the number of params              the da...
Should and avoid      Methods to be overloaded should perform the same task      The signatures of the overloaded must be ...
This keyword      refer to the current object of the class.      cannot use this keyword with static variables and method ...
Question?     https://gist.github.com/2349708
Constructors and Destructors
Constructors      initialization      no return type      possible to have overloaded constructors      https://gist.githu...
Default Constructors      C# creates a default constructors for a class if no constructor is      specified within the cla...
Static Constructors      initialize static variables of the class and to perform a particular      action only once.      ...
Constructor Overloading      https://gist.github.com/2344673
Destructors      invoked automatically when the objects are not in use      only one destructor in a class      cannot be ...
Garbage Collector
Upcoming SlideShare
Loading in...5
×

6 class and methods

484

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
484
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
29
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "6 class and methods"

  1. 1. Class and Method Programming in C# tnngo2@gmail.com
  2. 2. Class and Objects
  3. 3. Object-oriented programming Programming languages designed based on data and ways to manipulate data. Procedural Languages (Pascal, C) focus on ways Object-oriented Languages (C#, Java) focus on data
  4. 4. Features Abstraction Encapsulation Inheritance Polymorphism Focus only the required information from objects
  5. 5. Features Abstraction Encapsulation Inheritance Polymorphism Hide details of what a class contains
  6. 6. Features Abstraction Encapsulation Inheritance Polymorphism Create a new class based on the attributes and methods of an existing class
  7. 7. Features Abstraction Encapsulation Inheritance Polymorphism Behave differently in different situations
  8. 8. Class
  9. 9. Class – should & cannot Should be a noun first letter capitalized simple, descriptive, meaningful Cannot in mixed case C# keyword begin with a digit except @, _
  10. 10. Methods
  11. 11. Method – can & cannot Can begin with a letter, _ or @ Cannot C# keyword contain space begin with digit
  12. 12. Invoking methods https://gist.github.com/2349623
  13. 13. Static methods called without creating any objects of the class refer only to static variables and other static methods of class. https://gist.github.com/2349658
  14. 14. Static methods Only one copy of static variable is shared by all the objects of the class.
  15. 15. Question? https://gist.github.com/2349708
  16. 16. Access Modifiers
  17. 17. Access Modifiers
  18. 18. Ref causes arguments to be passed in a method by reference https://gist.github.com/2344456
  19. 19. Out similar to ref but no required the variables that are passed by reference to be initialized https://gist.github.com/2344483
  20. 20. Method overloading
  21. 21. Method overloading every method has a signature which comprises the number of params the data types of params the order of params
  22. 22. Should and avoid Methods to be overloaded should perform the same task The signatures of the overloaded must be unique Return type is not a part of the signature The ref and out parameters can be included as a part of the signature
  23. 23. This keyword refer to the current object of the class. cannot use this keyword with static variables and method https://gist.github.com/2344534
  24. 24. Question? https://gist.github.com/2349708
  25. 25. Constructors and Destructors
  26. 26. Constructors initialization no return type possible to have overloaded constructors https://gist.github.com/2344570
  27. 27. Default Constructors C# creates a default constructors for a class if no constructor is specified within the class. It automatically initializes all the numeric data type instance variables to zero. If you define a constructor in the class, the default constructor is no longer used.
  28. 28. Static Constructors initialize static variables of the class and to perform a particular action only once. is invoked before any static member of the class is accessed. does not take any parameters and does not use any access modifiers because it is invoked directly by the CLR instead of the object. Certainly, cannot access non-static data member. https://gist.github.com/2344643
  29. 29. Constructor Overloading https://gist.github.com/2344673
  30. 30. Destructors invoked automatically when the objects are not in use only one destructor in a class cannot be overloaded or inherited cannot be explicitly invoked cannot specify access modifiers and cannot take parameters https://gist.github.com/2344708
  31. 31. Garbage Collector
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×