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 locals and unsafe contexts in iterators and async methods
From the course: .NET 9 Maui: Enhanced Features for Cross-Platform Development
Enable ref locals and unsafe contexts in iterators and async methods
- [Instructor] The ref keyword allows us to access a value or reference type and change its value, or to protect the reference type from being pointed at by a different instance of an object. This is a reasonable usage in C#, but with the addition of the async and await keywords, they were limited in the use in those functions. This happened because C# did not know if the value or reference type that the ref keyword was pointed to would still exist after the asynchronous operation. This has been improved somewhat in C# 13. Now the ref keyword can be used in an async method with some limitations. For example, async method still cannot return or receive items using the ref keyword, nor can a ref local variable in the async method be retrieved from a ref returning function to be used after the await keyword. So let's take a look at an example. So on the start code for this chapter, we've got a new view model called RefLocalsViewModel. So we're going to open that up and we're going to…
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)
-
-