C#中变量和对象有什么区别

C#中变量和对象有什么区别

本文介绍了C#中变量和对象有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我说我有一个班级建筑

let's say that i have a Class Building

Building house = new Building();





现在我正在读一本书,上面写着



now i was reading in a book that say that

Quote:

这个声明执行三个功能。首先,它声明了一个名为House of

类类型Building的变量。这个变量本身不是一个对象。相反,它只是一个变量,

可以引用一个对象。

This declaration performs three functions. First, it declares a variable called house of the
class type Building. This variable is not, itself, an object. Instead, it is simply a variable that
can refer to an object.





然后我遇到了一个Answerin Stackoverflow说是那个



and then i am came across a Answerin Stackoverflow that say's that

引用:

如果你看一个例子,他很容易理解。例如,假设您有一个House House。你自己的房子是一个对象,是House之类的一个例子。你姐姐的房子是另一个对象(House的另一个例子

his is easy to understand if you look at an example. For example, suppose you have a class House. Your own house is an object and is an instance of class House. Your sister's house is another object (another instance of class House







// Class House describes what a house is
class House {
    // ...
}

// You can use class House to create objects (instances of class House)
House myHouse = new House();
House sistersHouse = new House();



现在我很困惑它是一个物体还是变量?

ps:我是C#的新手




我尝试了什么:



阅读了很多文章但很困惑


now i am confused whether it's an object or an Variable?
ps: i am new to C#


What I have tried:

read many articles but confused

推荐答案

 int i;
//  i is a variable name for the  value type  int




MyClass objMyClass ;
 //objMyClass is an object(variable name) of type MyClass which is a  reference type 



这篇关于C#中变量和对象有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 07:55