什么是VB的&QUOT相当于;模糊和QUOT;在C#中的语句? [英] What is the equivalent of VB's "Dim" statement in C#?

查看:202
本文介绍了什么是VB的&QUOT相当于;模糊和QUOT;在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

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 点心没有在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相当于;模糊和QUOT;在C#中的语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆