问题描述
我见过几个提到的咕哝打字,像这样的StackOverflow的答案:的
I've seen several mentions of "mumble typing," such as this StackOverflow answer: Will a future version of .NET support tuples in C#?
我用Google搜索这个词和我再也找不到比一些人希望C#最终会支持它更在解释的方式,其他。
I Googled the term and I couldn't find much in the way of an explanation, other than some people hoping that C# would eventually support it.
什么是喃喃打字?
推荐答案
我不知道是否有人在C#设计团队想出了这个词,或者如果它在行业中的其他位置使用。我们开始使用它,而工作的隐式类型的局部变量(即变种X =什么;)用C#3.0。一个相当常见的场景是希望编译器来推断一个类型的一部分,但更加明确一些,另一部分。例如,请考虑以下内容:
I don't know if someone on the C# design team came up with this term, or if it is used elsewhere in the industry. We started using it while working on implicitly typed local variables (that is "var x = whatever;") in C# 3.0. A fairly common scenario is to want the compiler to infer part of a type but be explicit about another part. For example, consider the following:
var list = new List<int>() { 10, 20, 30 };
下面的名单的类型没有给出,但泛型列表的类型参数给出。很多人认为,这可能从初始推断:
Here the type of "list" is not given, but the type argument of the generic list is given. One imagines that this could be inferred from the initializer:
var list = new List<???>() { 10, 20, 30 };
在这里?意思是有这么放在这里一个类型参数,编译器,找出它必须从上下文。
Here the ??? means "there's a type argument that goes here; compiler, figure out what it has to be from the context".
我们称之为嗯嗯打字,因为一个幽默地想象正在读取的代码为VAR名单等于十,二十,三十初始化hrmhmrhrm的新名单。
We call this "mumble typing" because one humourously imagines the code being read as "var list equals new list of hrmhmrhrm initialized with ten, twenty, thirty."
我们从未付诸实施咕哝打字,这是一个有点不幸的,因为它意味着它是很难使匿名类型的列表。要做到这一点,你可以使用的的把戏。
We never implemented mumble typing, which is a bit unfortunate because it means that it is hard to make a list of anonymous type. To do so, you can use the "cast by example" trick.
这篇关于什么是"咕哝打字"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!