什么是VB的"相当于;模糊和QUOT;在C#中的语句? [英] What is the equivalent of VB's "Dim" statement in C#?
问题描述
拿起C#,似乎无法找到任何有用的参考这个,比实例等。
Picking up C#, can't seem to find any useful reference to this, other than examples.
那么,什么是用C#有啥用?
So, what is Dim in C#?
推荐答案
在VB中,点心
声明特定类型的变量(或变量类型的如果你不指定一个)。如果您暗淡x作为富
,声明类富
名为 X 变量。code>
In VB, Dim
declares a variable of a particular type (or of variable type, if you don't specify one). If you Dim x as Foo
, that declares a variable of type Foo
called x
.
在C#中,相当于是陈述式后面是变量的名称,如:
In C#, the equivalent is to state the type followed by the variable's name, as in:
Foo x;
int i;
您也可以指定在相同的步骤:
You can also assign in the same step:
Foo x = new Foo();
int i = 6;
C#支持类型推断,所以你也可以这样做:
C# supports type inference, so you can also do:
// Compiler infers type of x and i based on this assignment.
var x = new Foo(); // x is now of type Foo
var i = 10; // i is now of type int
A 点心$ C $的C>没有在VB中相应类型类似于声明一个类型为
对象
在C#中:
A Dim
without a corresponding type in VB is similar to declaring a type as Object
in C#:
object o = ...; // An object instance can hold any value or reference type.
这篇关于什么是VB的"相当于;模糊和QUOT;在C#中的语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!