Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
let's say that i have a Class Building
Building house = new Building();


now i was reading in a book that say that
Quote:
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.


and then i am came across a Answerin Stackoverflow that say's that
Quote:
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();

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
Posted
Updated 23-Feb-17 18:18pm

Variable is just a name given to the type which we create
basically in c# everything is an object[^] (all the types are derived from object )

In simple words, For Value types[^] we will call it as variables [^] where as for reference type[^] we call it as object [^]

example:
C#
 int i; 
//  i is a variable name for the  value type  int

C#
MyClass objMyClass ;
 //objMyClass is an object(variable name) of type MyClass which is a  reference type 
 
Share this answer
 
v2
Google Search: c# variable vs object[^] had this gem: Value vs Reference Types in C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900