Simple and short, this is how you can initialize a variable in VB.NET. بسيطة وقصيرة ، وهذه هي الطريقة التي يمكنك تهيئة متغير في VB.NET.

Take the following for example: خذ على سبيل المثال ما يلي :
Dim dirInfo As System.IO.DirectoryInfo = New System.IO.DirectoryInfo("C:\")

The first part: الجزء الأول :
Dim dirInfo As System.IO.DirectoryInfo as I would like to call it, “dreams” about a variable dirInfo which belong to a type of System.IO.DirectoryInfo . Dim dirInfo As System.IO.DirectoryInfo كما أود أن يطلق عليه "أحلام" عن متغير dirInfo التي تنتمي إلى نوع من System.IO.DirectoryInfo.

The second part: الجزء الثاني :
New System.IO.DirectoryInfo("C:\") actually realizes your dream, it “creates” that variable. New System.IO.DirectoryInfo("C:\") في الواقع يدرك أحلامك ، أنه "يخلق" أن المتغير. It’s only now that your variable dirInfo trully exist. انها فقط الآن بأن ما تتمتعون به متغير dirInfo trully موجودة.

You can also initialize a variable like so: يمكنك أيضا تهيئة متغير مثل ذلك :
Dim dirInfo As System.IO.DirectoryInfo
dirInfo = New System.IO.DirectoryInfo("C:\")

One of the error message that you may get if you haven’t been initializing a variable correctly is “Object reference not set to an instance of an object” . واحدة من رسالة الخطأ التي قد تحصل إذا لم يتم تهيئة متغير بشكل صحيح هو معيار "لا إشارة إلى مجموعة من الجسم على سبيل المثال". The following code can cause an error, since the variable dirInfo is still a “dream”. الشفرة التالية يمكن أن تسبب خطأ ، لأن متغير dirInfo لا يزال "الحلم".

Dim dirInfo As System.IO.DirectoryInfo
dirInfo.GetDirectory("C:\")

As in life, good things starts with a dream, and you have to do something to it, before it can be realized. وكما في الحياة ، الأشياء الجيدة تبدأ مع حلم ، ولكم يجب أن نفعل شيئا لأنها ، قبل ذلك لا يمكن أن تتحقق.