Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

6 class and methods


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

6 class and methods

  1. 1. Class and Method Programming in C#
  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
  13. 13. Static methods called without creating any objects of the class refer only to static variables and other static methods of class.
  14. 14. Static methods Only one copy of static variable is shared by all the objects of the class.
  15. 15. Question?
  16. 16. Access Modifiers
  17. 17. Access Modifiers
  18. 18. Ref causes arguments to be passed in a method by reference
  19. 19. Out similar to ref but no required the variables that are passed by reference to be initialized
  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
  24. 24. Question?
  25. 25. Constructors and Destructors
  26. 26. Constructors initialization no return type possible to have overloaded constructors
  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.
  29. 29. Constructor Overloading
  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
  31. 31. Garbage Collector