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.
Allow ref struct types as arguments for type parameters in generics
From the course: .NET 9 Maui: Enhanced Features for Cross-Platform Development
Allow ref struct types as arguments for type parameters in generics
- [Instructor] In the last video, we learned how ref structures never move to the heap in memory and always remain in the stack. We also learned how they can now implement interfaces. In this video, we will expand on this and see how implementing an interface on a ref struct can now be used to allow it to be used as a type in a generic. The importance of having the ref struct implement the interface is so we have some type that we can then use to call methods and properties on. One thing to be aware of, since a ref struct has special handling of memory, it cannot be retained in an instance of a variable of a reference type. So even if a generic class allows a ref struct, it cannot retain a permanent reference to it because it can move out of the stack and into the memory heap, and this isn't allowed for a ref struct. However, a generic ref struct could retrain a permanent reverence to a generic type that allows a ref struct because both would be restricted to the stack. In the start…
Contents
-
-
-
-
-
-
(Locked)
Params collections4m 6s
-
(Locked)
New lock type and semantics3m 53s
-
(Locked)
New escape sequence: \e1m 48s
-
(Locked)
Method group natural type improvements4m 18s
-
(Locked)
Implicit indexer access in object initializers2m 49s
-
(Locked)
Enable ref locals and unsafe contexts in iterators and async methods3m 55s
-
(Locked)
Enable ref struct types to implement interfaces4m 43s
-
(Locked)
Allow ref struct types as arguments for type parameters in generics5m 50s
-
(Locked)
Partial properties and indexers6m 21s
-
(Locked)
Overload resolution priority4m 4s
-
(Locked)
-
-