From the course: .NET 9 Maui: Enhanced Features for Cross-Platform Development

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Enable ref struct types to implement interfaces

Enable ref struct types to implement interfaces

- [Instructor] A C# structure is a value type that can track multiple values and associated functionality. However, it is not a reference type. That means it can't do boxing or unboxing operations, nor can a structure participate in inheritance as a base or derived class. But in many ways, a structure can be thought of as a lightweight, high performing class. A ref structure is a type of structure that takes another step down that road. It is treated in memory differently than a standard structure or reference type. In memory, a ref structure lives exclusively on the stack and cannot be moved to the managed heap. This means it is much faster to reference and release memory it resides in. However, the ref structure came with some limitations. One of them being that it could not implement interfaces like a normal structure. With C# 13, this has changed and ref structures can now implement interfaces. It is still a value type instead of a reference type, so it can't undergo boxing. In…

Contents