关于c .........简单 [英] simple about c.........

查看:69
本文介绍了关于c .........简单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

声明和定义变量之间有什么区别?
什么是变量无效化?

what is the Difference between Declaring and defining a variable?
what is variable inilization?

推荐答案

可能会有所帮助,

5.变量 [ ^ ]

在MSDN中的第5节(5.变量)下,有5.1、5.2、5.3、5.4、5.5子节,这些子节对变量有很好的描述.

:)
It might be helpful,

5. Variables[^]

in the MSDN under section 5 (5. Variables)there are sub sections 5.1,5.2,5.3,5.4,5.5 which has good description about the Variables.

:)


我认为您需要退后一步,弄清楚.NET中的值类型和引用类型之间的区别是什么,以及它们如何存储在内存中被创建和使用.

您可以在代码中声明"变量:它们可能会或可能不会自动初始化"为某个默认值,具体取决于几个因素(通过了解值和引用类型可以了解这些因素).

我发现已定义"一词的用法有点模棱两可,因为:有时它的含义与声明的含义相同,而有时它的含义是为变量分配了一个值,或(引用类型)变量已实例化

认为您将值分配"给值"类型变量,但是却创建了引用类型的实例"可能会有所帮助.如果是字符串"类型,它会有点复杂,这里有关于这种复杂性的很好的讨论[ ^ ].

获得有关C#的好书,也许是来自Jesse Liberty的书,并获得有关".NET类型"和变量"的基础"知识;从那里,您可以考虑使用静态"类型还是非静态类型,依此类推.

现在进行一些研究,以后您就可以解决很多问题.

最好,比尔
I think you need to take one step back, and get clear about what the difference is between Value types and Reference Types in .NET, and how they are stored in memory as they are created and used.

You "declare" variables in your code: they may or may not be automatically ''initialized'' to some default value, depending on several factors (which you can understand by getting clear about Value and Reference Types).

I find the use of the word "defined" a little ambiguous because: at times it''s used to mean the same thing as declared, and at other times it''s used to mean the variable has a value assigned to it, or the (reference Type) variable has been instantiated

It may be helpful to think that you "assign values" to Value type variables, but you "create instances" of reference types. In the case of the ''string'' type it gets a bit complex, and there''s a good discussion of that complexity here[^].

Get a good book on C#, perhaps one from Jesse Liberty, and get "grounded" on what .NET Types are, and what variables are; from there you can consider the use of ''static'' vs. non-static Types, and so forth.

A little study now, and you can solve so many problems later.

best, Bill


There is big deference between declaring and defining a variable

//when you write this then it means declaring a variable
int a;

//or 
float b;


// when you assign any value to that variable is called defining

a = 10;
//Or
b =22.56;
// you can also write this type of statements its called defining at declaration time
int a = 10;
//or 
float b = 22.56;
//or 
float c = a/b;


这篇关于关于c .........简单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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