- 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;
}
- WildFly:New Features
- Objective-C應用開發全程實錄
- Python Deep Learning
- 基于差分進化的優化方法及應用
- WordPress Plugin Development Cookbook(Second Edition)
- Spring Boot進階:原理、實戰與面試題分析
- Julia for Data Science
- HTML+CSS+JavaScript網頁設計從入門到精通 (清華社"視頻大講堂"大系·網絡開發視頻大講堂)
- C語言程序設計簡明教程:Qt實戰
- Everyday Data Structures
- Instant Zurb Foundation 4
- Functional Python Programming
- 金融商業數據分析:基于Python和SAS
- Java自然語言處理(原書第2版)
- Implementing Domain:Specific Languages with Xtext and Xtend