UScript for Unturned Understanding Some Fundamentals

From Free Knowledge Base- The DUCK Project
Jump to navigation Jump to search

OOP concept distinctions: variable, array, object, and property

Here’s a clear distinction between these four concepts:

Variable

A named storage location that holds a value. It can store different types of data, such as numbers, strings, or objects.

Example:

health = 100;

Array

A collection of multiple values stored in a single variable. Each value (element) is accessed using an index.

Example:

int[] scores = {90, 85, 78};

Access:

scores[0] returns 90

Object

An instance of a class that can contain multiple variables (fields) and functions (methods). Objects group related data and behavior together.

Example:

class Player {
    string name;
    int health;
}
Player p = new Player();

Property

A special type of variable inside an object that controls access to data. Properties can have getters (to retrieve values) and setters (to modify values).

Example:

class Player {
    public int Health { get; set; }
}
Player p = new Player();
p.Health = 100;

In an array: array.length is a property that returns the number of elements.