DEV Community

PeterMilovcik
PeterMilovcik

Posted on

 

When to use record instead of class in .NET?

In .NET, the record keyword is used to create a value type that is a light-weight alternative to a class. record types are similar to classes, but they are immutable and come with built-in support for value-based equality, copy and move semantics, and pattern matching. record types are particularly useful for scenarios where you need to represent a value that is not intended to be modified, such as a mathematical vector or a geographic coordinate.

In general, you should use record instead of class when you need a value type that is lightweight, immutable, and provides built-in support for value-based equality, copying, and pattern matching. If you need a reference type that is mutable or you require additional features that are not supported by record types, such as inheritance or polymorphism, then you should use a class instead.

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.