有人可以解释一下元组是什么以及如何在真实世界场景中使用它.我想知道这如何丰富我的编码经验?
我正在研究元组的新C#特性.我很好奇,元组设计要解决什么问题?
您在应用中使用了什么元组?
更新
感谢到目前为止的答案,让我看看我是否在脑子里直截了当.已经指出了元组的一个很好的例子作为坐标.这看起来不错吗?
var coords = Tuple.Create(geoLat,geoLong);
Run Code Online (Sandbox Code Playgroud)
然后像这样使用元组:
var myLatlng = new google.maps.LatLng("+ coords.Item1 + ", "+ coords.Item2 + ");
Run Code Online (Sandbox Code Playgroud)
那是对的吗?
这里我不是在谈论某种特定的编程语言。我想知道不同数据结构之间这些东西有什么区别。我认为列表基本上应该是可调整大小的,而数组则不是,但我不确定。
我创建了一个方法:
\npublic static Tuple<string, string, string> SplitStr(string req)\n{\n //...\n return (A, B, C)\n}\nRun Code Online (Sandbox Code Playgroud)\n它抱怨说"CSOOZQ: Cannot implicitly convert type '(strinq _keyword, strinq _filterCondition, strinq _filterCateqory)' to 'System.Tuple<strinq, strinq, string)\xe2\x80\x98"
但如果代码:
\npublic static (string, string, string) SplitStr(string req)\n{\n //...\n return (A, B, C)\n}\nRun Code Online (Sandbox Code Playgroud)\n错误消失。从错误来看,元组的括号形式和元组的括号形式Tuple<>不同。
Tuple<>?如何返回元组?谢谢。
\n