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

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;
}
主站蜘蛛池模板: 白银市| 平果县| 成安县| 阜南县| 镇巴县| 甘南县| 德江县| 濉溪县| 宾川县| 治多县| 巴林左旗| 乌恰县| 邓州市| 三台县| 望都县| 福清市| 河池市| 通城县| 祁东县| 雅安市| 玛多县| 河西区| 崇义县| 衡阳市| 鄱阳县| 东台市| 八宿县| 泾川县| 留坝县| 鹿泉市| 天全县| 通州市| 万安县| 馆陶县| 镇远县| 三门峡市| 雅江县| 宽城| 云龙县| 武平县| 南宫市|