struct
A C# value type declared with the struct keyword, copied in full whenever it is assigned or passed.
In more detail
Structs suit small values with no identity, such as a size or an amount. Changing a copy never changes the original, unlike a class.
Example
struct Size { public int Width; }Related terms
- value type — A type whose variables hold the data itself, so assigning one to another copies the whole value.
- class — A blueprint in code that bundles data and the functions that work on it, from which objects are made.
- record struct — A record declared as a value type, with the same generated members but copied by value and not allocated on the heap.
Taught in
- The C# Language: Types, Variables, and Flow Control — Modern .NET Core, C# & Enterprise Microservices