6 class and methods

689 views
597 views

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
689
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
35
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

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

×