- C# and .NET Core Test Driven Development
- Ayobami Adewole
- 207字
- 2021-06-25 22:00:35
Tuples enhancement
Tuples were introduced into C# language in Version 4 and are used in the simplified form to provide structure with two or more data elements, allowing you to create methods that can return two or more data elements. Before C# 7, referencing the elements of a tuple was done by using Item1, Item2, ...ItemN, where N is the number of elements in the tuple structure. Starting from C# 7, tuples now support semantic naming of the contained fields with the introduction of cleaner and more efficient ways of creating and using tuples.
You can now create tuples by directly assigning each member to a value. This assignment creates a tuple containing elements Item1, Item2:
var names = ("John", "Doe");
You can also create tuples that have semantic names for the elements contained in the tuple:
(string firstName, string lastName) names = ("John", "Doe");
The names tuple, instead of having fields as Item1, Item2, will have fields that can be referenced as firstName and lastName at compile time.
You can create your method to return a tuple with two or more data elements when using POCO might be overkill:
private (string, string) GetNames()
{
(string firstName, string lastName) names = ("John", "Doe");
return names;
}
- HTML5+CSS3+JavaScript從入門到精通:上冊(微課精編版·第2版)
- 玩轉Scratch少兒趣味編程
- Python機器學習:數據分析與評分卡建模(微課版)
- Java面向對象思想與程序設計
- Building a RESTful Web Service with Spring
- 架構不再難(全5冊)
- Vue.js快跑:構建觸手可及的高性能Web應用
- Learning Flask Framework
- Learning Neo4j 3.x(Second Edition)
- 前端HTML+CSS修煉之道(視頻同步+直播)
- Express Web Application Development
- Azure Serverless Computing Cookbook
- Clean Code in C#
- jQuery for Designers Beginner's Guide Second Edition
- Software Development on the SAP HANA Platform