为什么数据库在不使用新关键字的情况下正常显示? [英] Why the datamembers appeared normally without using new keyword ?

查看:70
本文介绍了为什么数据库在不使用新关键字的情况下正常显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





可能是问题不明确但我真的需要了解。

i将解释



如果我有一个名为Test的类包含2个公共int变量。

Hi ,

May be that the question in not clear but i really need to understand.
i will explain

if i have class called Test contain 2 public int variable .

class Test
{
public int x;
public int y;
}





如果我宣布Test类的新对象而不使用new keyward初始化它

如下所示



if i declare a new object of Test class without initialize it using new keyward
like below

class Main()
{
Test t;
t.x //appeared
t.y //appeared
}





为什么x和y在点运算符之后正常访问???

i知道它们是公开的但是我的问题与新的keyward有关。

是否有任何目的来自显示他们没用,因为我们并没有使用新的键控,对吧???那么为什么visual studio会在intellisense中显示它呢?另外一个问题:我需要一个能够清楚地描述抽象和封装之间差异的链接,......有很多文章,但我很困惑,大多数文章互相混淆。



why x and y are being accessed normally after dot operator ???
i know that they are public but my question is related with new keyward.
is there any purpose from showing them , they are useless because we don't use new keyward , right ??? so why visual studio show it in intellisense

another question : i need a link that describe clearly the difference between abstraction and encapsulation ,......there are many articles but i am confused and most of articles are confused with each other .

推荐答案

因为 int 变量是值类型,而不是引用,而值类型不需要 new



参考变量指向实际数据,值变量 实际数据。因此声明为变量创建了整个空间,而不是为引用(或指针)分配enout空间。

这适用于所有值类型,因此如果声明 struct 你会发现同样的事情:

Because int variables are Value types, not reference, and Value types do not need new.

A Reference variable "points" at the actual data, a Value variable is the actual data. So the declaration creates the whole space for the variable, instead of allocating enout space the the reference (or pointer).
This works for all Value Types, so if you declare a struct you will find the same thing:
public struct MyStruct
    {
    public int i;
    public string s;
    }




...
MyStruct ms;
ms.i = 66;
ms.s = "hello";
....


这篇关于为什么数据库在不使用新关键字的情况下正常显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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