cprog 2

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/52

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

53 Terms

1
New cards

2D array

A data structure that consists of a collection of elements organized in rows and columns, allowing for efficient storage and manipulation of grid-like data.

2
New cards

Methods

It is a block of codes that perform a specific task.

3
New cards

CONSTRUCTORS

Is the special method called when instantiating a class or create an object. It is used to initialize the attributes of an object or run a block of code when an object is created.

4
New cards

Encapsulation

The principle of bundling the data and methods that operate on the data within a single unit, or class, and restricting access to some of the object's components.

5
New cards

Argument

A value passed to a method or constructor when it is called, which can influence its behavior and output.

6
New cards

In declaring 2D arrays

the array elements must have the same number of values or columns. In declaring 2D arrays, rows and columns values cannot be interchange.

7
New cards

.GetLength

(row/column) may be used to get the number of rows or columns in a 2D array.

8
New cards

Static

means that the method belongs to the Program class and not an object of the Program class

9
New cards

Void

a keyword used to specify that a method does not return a value.

10
New cards

Global Variables

variables that are accessible from any method within a program, typically declared outside of all functions.

11
New cards

Local Variables

variables defined within a method, which can only be accessed inside that method.

12
New cards

METHOD PARAMETERS

13
New cards

METHODS WITH DEFAULT PARAMETER VALUE

Also known as optional parameter.

Every optional parameter contains a default value which is part of the definition.

Equal sign (=) is used in declaring a default parameter value in the method statement.

Default value is used when the method is called without an argument.

The optional parameters are always defined at the end of the parameter list

14
New cards

NAMED ARGUMENTS

  • It enables to specify an argument for a parameter by matching the argument with its name rather than with its position in the parameter list.

• When used, the arguments are evaluated in the order in which they appear in the argument list not in the parameter list.

15
New cards

RETURN KEYWORD

It is used to return a value from the method.

16
New cards

METHOD OVERLOADING

An important feature of Object-Oriented Programming that refers to the ability to redefine a method in more than one form.

17
New cards

METHODS WITH RETURN

Values returned from return keyword may be stored in a variable after calling method.

Values may also be printed after returned in the calling method inside Console.WriteLine method.

18
New cards

CLASSES

It is created by the programmer.

It will act as a blueprint of an object that will be implemented in the program.

They contain all the attributes and methods of an object.

19
New cards

CLASS INSTANTIATION

The process of creating an instance of a class so it can be used in the program.

Can also be called objects.

Multiple instances of a class can be created

20
New cards

Access Modifiers

Used to modify where classes, variables and methods are accessible

21
New cards

default or internal

The class can only be accessed in the same assembly not other assemblies.

22
New cards

public

The class can be accessed in all classes.

23
New cards

default or private

It can only be accessible inside its own class.

24
New cards

internal

The methods and variables can only be accessed in the same assembly not other assemblies.

25
New cards

protected

It can only be accessed in the same class or in a class that is inherited from that class.

26
New cards

readonly Keyword

keyword used so that a variable cannot be reassigned to a new value.

27
New cards

OBJECT-ORIENTED PROGRAMMING

It focuses on implementing real world objects using Classes to create variations of Objects, that has attributes and purpose.

• It helps us create much flexible and efficient code than procedural programming.

28
New cards

fields and methods

Fields and methods inside a class are called class members.

29
New cards

ATTRIBUTES / FIELDS

These are the global variables declared inside the class of an object.

• It is used to create variations of an object using only one class.

• Can be accessed by creating an object of the class, and by using the dot syntax ( . )

30
New cards

METHODS

These are used to perform certain actions.

• They define how an object of a class behave.

• Just like attributes/field, it can access with dot syntax ( . )

31
New cards

OBJECTS

It is created by instantiating a Class. It is anything that has an attribute and a purpose. It is an instance of a class. It holds data and can access methods and their properties. Ex. Person, Furniture, Food.

32
New cards

State

It is represented by attributes of an abject, and reflects the properties of an object

33
New cards

Behavior

It is represented by the methods of an object and also reflects the response of an object with other objects.

34
New cards

Identity

It gives a unique name to an object and enables one object to interact with other objects.

35
New cards

CLASS INSTANTIATION

  • The process of creating an object using a class so that it can be used in the program.

• All the instances share the attributes and the behavior of the class. But the values of those attributes are unique for each object.

• A single class may have any number of instances.

36
New cards

new keyword

is used to create an object of the class.

37
New cards

CONSTRUCTORS

Is the special method called when instantiating a class or create an object.

It is used to initialize the attributes of an object or run a block of code when an object is created.

Constructor method are named after their Class Name and it cannot have a return type (like void or int).

38
New cards

Default Constructor

Created automatically by C# if not defined. A constructor with an empty code and no parameters. It has every instance of the class to be initialized to the same value. It initializes all numeric field to zero and all string and object fields to null inside a class.

39
New cards

Parameterized Constructor

A constructor that have at least one parameter. It can initialize each instance of the class to different values. The values passed to the constructors are called arguments. Values must be the same number and type of values as parameters.

40
New cards

Copy Constructor

Used to create an object by copying data from another object of the same class. Useful when you need to duplicate an object or create a new object based on the state of another.

41
New cards

Private Constructor

It is when a constructor is created with a private specifier. It is impossible for other classes to derive from this class and it’s not possible to create an instance of this class. It is the implementation of the singleton class pattern. Can be used when class members are static. Can be accessed using the class name.

42
New cards

Static Constructor

A constructor that must be invoked only once in the class and it has been invoked during the creation of the first reference to a static member in the class. It initialized static fields or data of the class and is to be executed only once. It can’t be called directly. It does not take access modifiers or any parameters. It is called automatically to initialize the class before the first instance is created. Only one static constructor in a class.

43
New cards

this keyword

It refers to the class itself. It will enable to access global variables inside the class if you have the same variable names in the parameter. Cannot be used when variables in the parameter is not the same names with global variable. It refers to the current instance of the class.

Example

44
New cards

Automatically Add Constructor

Use Quick Actions (Ctrl + . )
Type ctor and tab key.

45
New cards

Object Methods

Are methods declared inside an object class.

It is considered as the object’s purpose.

46
New cards

Encapsulation

It is an OOP technique used to hide data from direct access.

The variables or data of a class are hidden from any other class and can be accessed only through any member function of its class in which they are declared.

It is also known as data-hiding.

It can be achieved by declaring all the variables in the class as private and using C# Properties in the class to set and get the values of variables.

47
New cards

Data protection and control

Data can be validated and controlled before storing in the variable.

48
New cards

Achieving Data Hiding

The user will have no idea about the inner implementation of the class.

49
New cards

Security

Helps to secure code since it ensures that other units(classes, interfaces, etc) can not access the data directly.

50
New cards

Flexibility

Makes code more flexible, allowing the programmer to easily change or update the code.

51
New cards

Getters & Setters

These are used to get and set encapsulated variables.

Note :
Do not use the name for the field and property.

Acts as the middleman between the main class access to the private field.

Create a getter and setter for every private field.

Property must be declared public so the main class can access it.

Remove the set line if the variable is read-only and get line if the variable is write-only.

52
New cards
53
New cards