الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

شرح يوضح الفرق بين Reference Type وال Value Type

مغلق
بدأه اللهم أنصر الاسلام والمسلمين في 9 يوليو 2007 · 3 رد · 4,504 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

What Is a Reference Type?

Reference types store the address of their data, also known as a pointer, on the stack. The actual data that address refers to is stored in an area of memory called the heap. The runtime manages the memory used by the heap through a process called garbage collection. Garbage collection recovers memory periodically as needed by disposing of items that are no longer referenced.

Comparing the Behavior of Reference and Value Types

Because reference types represent the address of data rather than the data itself, assigning one reference variable to another doesn’t copy the data. Instead, assigning a reference variable to another instance merely creates a second copy of the reference, which refers to the same memory location on the heap as the original variable.

Consider the following simple structure declaration:


{
static void Main(string[] args)
{
Numbers n1 = new Numbers(0);
Numbers n2 = n1;
n1.val += 1;
n2.val += 2;
Console.WriteLine("n1={0},n2={1}", n1, n2);
}
}
struct Numbers
{
public int val;
public Numbers(int _val)
{ val = _val; }
public override string ToString()
{ return val.ToString(); }
}
class Program

This code would display “n1 = 1, n2 = 2” because a structure is a value type, and copying a value type results in two distinct values. However, if you change the Numbers type declaration from a structure to a class, the same application would display “n1 = 3, n2 = 3”.

Changing Numbers from a structure to a class causes it to be a reference type rather than a value type. When you modify a reference type, you modify all copies of that reference type.

تم تعديل هذه المشاركة بواسطة اللهم أنصر الاسلام والمسلمين في 9 يوليو 2007 في 00:33

نور حياتك بالهدى.... واسلك طريق التائبين... وأعمر فؤادك بالتقى ....فالعمر محدود السنين وارضِ الإله بطاعة.... تسعدك في دنيا ودين.... واحمل بصدرك مصحفاً.... يشرح فؤادك كل حين ودع الغواية إنها.... لشقاوة للغافلين.... الدين مشكاة الحياة.... يضئ درب الحائرين عد للكريم بتوبة.... واركب جناح العائدين.... تلقى السعادة كلها.... فلنعم درب الصالحين

#2

السلام عليكم

شرح جيد تستحق عليه الشكر

ياريت لو الفرق بين output paramters وال reference paramters وال array paramters

معلش اصل اخوك زنان شوية

وشكرا مرة تانية

#3

اتفضل الينك دة

http://msdn2.microsoft.com/en-us/library/s...f28(VS.80).aspx

نور حياتك بالهدى.... واسلك طريق التائبين... وأعمر فؤادك بالتقى ....فالعمر محدود السنين وارضِ الإله بطاعة.... تسعدك في دنيا ودين.... واحمل بصدرك مصحفاً.... يشرح فؤادك كل حين ودع الغواية إنها.... لشقاوة للغافلين.... الدين مشكاة الحياة.... يضئ درب الحائرين عد للكريم بتوبة.... واركب جناح العائدين.... تلقى السعادة كلها.... فلنعم درب الصالحين

#4

مشكور اخوي على الشرح

هذا الموضوع مغلق.

مواضيع مشابهة