C#变量初始化VS分配 [英] C# variable initializations vs assignment

查看:206
本文介绍了C#变量初始化VS分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一本书,我发现了以下(翻译):

In a book I found following (translation):

初​​始化装置在声明时间分配变量的值。 INT X = 5 叫做初始化命令。

Initialization means assigning the value of the variable at the declaration time. int X=5 is called an initialization command.

编辑:这只是说这个词初始化仅当你在声明时赋值。如果以后做,它只是assignement(根据它 - 我不这么认为,这就是为什么我要求)。它是真的还是假的?

It just says that term initialization is used only when you assign value at the declaration time. If you do it later, its just assignement (according to it - I do not think so and that is why I am asking). Is it true or not?

嗯,我一直认为(并根据他人在网上,太)关于初始化一个值给一个变量的首次转让的条款。我认为, INT X = 5 只是分配作为声明的一部分。

Well, I have always thought (and according to others on the net, too) about initialization in the terms of first assignment of a value to a variable. I think that int X=5 is just assignment as a part of declaration.

我试着在MSDN上搜索,没有运气。感谢您的任何信息。

I tried to search on MSDN with no luck. Thanks for any information.

推荐答案

如果你问的是术语(*这是不是真的清楚从你的问题),初始化的变量是,从字面上看,第一时间的值被分配给它。这个词来自于你是给变量它的初始值的事实。

If all you are asking about is terminology (*which isn't really clear from your question), "Initialization" of a variable is, literally, the first time a value is assigned to it. This term comes from the fact that you are giving the variable it's "initial" value.

这应该(显然)发生之前使用它的第一次。

This should (obviously) happen before it is used the first time.

int x=5;

是一个声明和初始化,而真的只是方便速记

is a declaration and an initialization, and is really just convenient shorthand for

int x;
x=5;

这篇关于C#变量初始化VS分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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