官术网_书友最值得收藏!

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;
}
主站蜘蛛池模板: 兴安盟| 台南市| 肃南| 淳安县| 义马市| 怀远县| 金川县| 定州市| 仪陇县| 稷山县| 丹巴县| 晋中市| 那坡县| 沿河| 泸溪县| 博乐市| 英德市| 略阳县| 隆尧县| 洛浦县| 嘉荫县| 丹凤县| 南陵县| 大港区| 江陵县| 余庆县| 陵水| 肇东市| 沁源县| 泰州市| 岱山县| 诏安县| 右玉县| 高台县| 涪陵区| 麻城市| 白水县| 陇川县| 奉节县| 玉龙| 阳西县|