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

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;
}
主站蜘蛛池模板: 津市市| 衡南县| 通州市| 交口县| 淮滨县| 苏尼特右旗| 灌阳县| 乌鲁木齐市| 寿阳县| 伊金霍洛旗| 衡山县| 扬中市| 乾安县| 兴宁市| 米泉市| 青田县| 阳高县| 平远县| 尼勒克县| 高台县| 聂荣县| 内江市| 漯河市| 茌平县| 易门县| 东辽县| 库车县| 克什克腾旗| 肇东市| 正宁县| 巨野县| 乌海市| 贡觉县| 保德县| 山东省| 泰兴市| 微山县| 绥棱县| 饶阳县| 晋州市| 保定市|