- C# 7 and .NET Core Cookbook
- Dirk Strauss
- 169字
- 2021-07-03 00:11:55
Generalized async return types
If you use async/await (if not, check it out) the following feature of C# 7.0 will come in really handy. The only supported return types used to be Task<T>, Task, and void. Even then, void was also only used with event handlers such as a button click. The challenge, however, was that a Task<T> was allocated in situations where the result of the async operation was available at the time of awaiting. But, what does this even mean? Well consider an async method that returns a Task<T> : and that value has a time to live of n amount of seconds. If the async method is called within the time to live period, why go to the trouble of allocating another Task<T> object? This is where the ValueTask<T> comes into play; it will allow other types to be defined so that you can return them from an async method. This, therefore, reduces the Task<T> allocations, which in turn will lead to performance gains.
- 玩轉(zhuǎn)Scratch少兒趣味編程
- Hyper-V 2016 Best Practices
- TypeScript Blueprints
- 云原生Spring實(shí)戰(zhàn)
- Getting Started with SQL Server 2012 Cube Development
- ADI DSP應(yīng)用技術(shù)集錦
- GameMaker Programming By Example
- C語言程序設(shè)計(jì)上機(jī)指導(dǎo)與習(xí)題解答(第2版)
- Scratch3.0趣味編程動(dòng)手玩:比賽訓(xùn)練營(yíng)
- C指針原理揭秘:基于底層實(shí)現(xiàn)機(jī)制
- Windows Phone 8 Game Development
- LabVIEW入門與實(shí)戰(zhàn)開發(fā)100例(第4版)
- Android開發(fā)權(quán)威指南(第二版)
- Appcelerator Titanium Smartphone App Development Cookbook
- 前端Serverless:面向全棧的無服務(wù)器架構(gòu)實(shí)戰(zhàn)