THE CHEAT CODE TO MASTERY IN C#
GirlGotGoals)
KESHANI RAJKARAN
, CLASSES
What is a class?
• A class is a blueprint for an object.
• What does it define?
• Attributes - Fields/properties
• Methods - What it does (behavior)
How to add a class in Visual Studio
1. In solution explorer, right click your project ➡ Add ➡ Class
2. Name your project with the following naming Convention: ProjectName.cs
3. Let's create a class called Person, this is what your code should look like:
class Person
{
//enter attributes, objects and method code here
}
Attributes, Methods and Creating Objects from Classes
What is a property?
It is like a variable inside a class, but it has a lot more of control.
It usually has two parts to it.
Get: How you return values (how values are being read)
Set: How you assign values (how values are being saved)
How do you create an attribute in classes that can later be accessed by all
objects?
public datatype AttributeName ;
Here is an example: Create an attribute called name with a string datatype
class Person
{
public string name;
}
How do you create a method in a class that can later be accessed by all
objects?
public void MethodName ()