property
A named value belonging to an object; in languages such as C# and Python, it can also be a member that looks like a field but runs code when read or written.
In more detail
Properties let a type expose data while controlling how it is read and written. In JavaScript, a property whose value is a function is called a method, and properties can be added, changed and deleted at run time. Frameworks often discover properties automatically, for example to serialise objects to JSON.
Examples
public decimal Price { get; set; }public int Units { get; private set; }V8 remembers the order in which properties were added as an object's hidden class, so adding them in the same order keeps code fast.In Python, a method marked @property is read like an attribute: rect.area instead of rect.area().Related terms
- field — A variable declared inside a class that stores part of an object's state.
- init accessor — A property accessor written init instead of set, which allows the value to be assigned only while the object is being created.
- required modifier — The C# required keyword on a property, which makes the compiler refuse any construction that does not set it.
- expression-bodied member — A method or property whose body is a single expression written after =>, such as public bool InStock => Units > 0;.
- reflection — Code inspecting types, properties and methods at run time instead of knowing them at compile time.
- object — A single thing created from a class or other type, holding its own values and able to run the type's methods.
- method — A function that belongs to an object or type and is called on a value of it, as in name.upper().
- hidden class — An internal record V8 keeps of an object's property names and their order, so it can find properties quickly.
- decorator — A line starting with @ placed above a function or class that wraps it to add behaviour or information.
- attribute — A named value attached to an object and reached with a dot, such as point.x or math.pi; methods are attributes too.
Taught in
- Classes, Interfaces, and Object-Oriented C# — Modern .NET Core, C# & Enterprise Microservices
- The Options Pattern: Strongly Typed Configuration — Modern .NET Core, C# & Enterprise Microservices
- Entity Framework Core: Code First and Migrations — Modern .NET Core, C# & Enterprise Microservices
- V8 Engine & JIT Pipeline: Bytecode & Turbofan — Node.js Internals & Backend Services
- Sample Graphics Programs — Hands-on Python: Complete Video Course & Book
- HTML Forms And Dynamic Programs — Hands-on Python: Complete Video Course & Book
- Lists, Tuples, Sets, Dicts: Choosing One — Hands-on Python: Complete Video Course & Book
- Methods, Attributes And self — Hands-on Python: Complete Video Course & Book