隐式类型VS匿名类型类型、隐式、VS

2023-09-03 21:49:28 作者:草民

它是相同的或者是不同的,所以什么是隐式类型的和匿名类型之间的主要区别隐式类型的和匿名Type.If什么区别吗?

Is it same or any difference between Implicitly Typed and Anonymous Type.If it is different so What is the main difference between Implicitly Typed and Anonymous Type?

推荐答案

有一个巨大的差别:

隐式类型(本地)变量,是哪种类型的未明确给​​出变量:

Implicitly typed (local) variables, are variables which type is not explicitly given:

var i = new StringBuilder();

现在,隐式类型的的StringBuilder - 命名类型

Now, i is implicitly of type StringBuilder - a named type.

在另一边匿名类型没有名字,他们的匿名的:

Anonymous types on the other side do not have a name, they are anonymous:

var x = new { Foo = "Bar" };

现在x是一个匿名类型,具有只读属性

x is now of an anonymous type, with a read-only property Foo.