what is a C# reference type
-
I just started learning .Net and C#. I come from C++ background. When I declare a class vble // class A is defined; A a; a = new A(); This object a is allocated in heap right? and its a reference type? It seams all class variables are reference types. And it looks like a class pointer to me when I relate to C++. Any good article? thanks, Misha Evil traiumphs when good people sit quiet...
-
I just started learning .Net and C#. I come from C++ background. When I declare a class vble // class A is defined; A a; a = new A(); This object a is allocated in heap right? and its a reference type? It seams all class variables are reference types. And it looks like a class pointer to me when I relate to C++. Any good article? thanks, Misha Evil traiumphs when good people sit quiet...
-
I just started learning .Net and C#. I come from C++ background. When I declare a class vble // class A is defined; A a; a = new A(); This object a is allocated in heap right? and its a reference type? It seams all class variables are reference types. And it looks like a class pointer to me when I relate to C++. Any good article? thanks, Misha Evil traiumphs when good people sit quiet...
misha_grewal wrote:
This object a is allocated in heap right? and its a reference type?
Correct.
It seams all class variables are reference types.
That's right. A class is always a reference type, and a struct is always a value type.
And it looks like a class pointer to me when I relate to C++.
A reference is implemented as a pointer, but it's easier to use in the code. You don't have to dereference a reference to get to the object, as you do with a pointer.
--- single minded; short sighted; long gone;