ClassMembers.md - brainchildservices/curriculum GitHub Wiki
Slide 1
C# Class Members
Class members are members declared in the class and all those (excluding constructors and destructors) declared in all classes in its inheritance hierarchy.
Some of the class members are:
-
Constants representing constant values
class Calendar { public const int Months = 12; }
Here Month is an integer constant which is assigned value 12. Since its declared as const. The value of the Months never changes.
Slide 2
-
Fields representing variables: Any variable that is declared directly inside a class is called a field.
class Students { public string name; public int rollNo; }
-
Methods providing services like calculation or other actions on its members: Methods
-
Properties that define the class features and include actions to fetch and modify them. Properties
Slide 4
Exercise:
Q1. Create a class Human. Inside class Human declare a string field name & ethnicity, declare a constant legs of type integer.Assign values after creating the object.
Q2. Create a class Mountains. Inside class Mountains, declare fields string location, integer height.Assign values after creating the object
Q3. Create a class Fruits. Inside class Fruits declare fields name, price, color.Assign values after creating the object