- 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;
}
- 程序員面試白皮書
- Git Version Control Cookbook
- Manga Studio Ex 5 Cookbook
- Go語言高效編程:原理、可觀測性與優(yōu)化
- Python王者歸來
- OpenShift在企業(yè)中的實踐:PaaS DevOps微服務(wù)(第2版)
- 人人都懂設(shè)計模式:從生活中領(lǐng)悟設(shè)計模式(Python實現(xiàn))
- 網(wǎng)站構(gòu)建技術(shù)
- Android系統(tǒng)下Java編程詳解
- Python大規(guī)模機(jī)器學(xué)習(xí)
- Practical Maya Programming with Python
- 讀故事學(xué)編程:Python王國歷險記
- Serverless工程實踐:從入門到進(jìn)階
- Python AI游戲編程入門:基于Pygame和PyTorch
- 深入淺出Go語言核心編程