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

هل هناك فرق بين تعريف مصفوفه من الcalsses

مغلق
بدأه طارق إبراهيم في 9 أبريل 2004 · 1 رد · 611 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

سؤال محيرنى عند تعريف مصفوفه من نوع كلاس معين لا يمكننى التصريح declarationو الاستهلال intialization فى نفس الوقت

فكان لابد من كتابة الكود كالاتى

'in declaration section for example
dim obj_arr() as myclass
'array index
dim i as int16
'then in any part of the code
redim obj_arr(i)
obj_arr(i)= new myclass

و السؤال هنا لماذا لم نستطع عمل ال declaration و ال intialization فى نفس الوقت كما هو الحال عند تعريف مصفوفه من اى نوع اخر

وهل هذا هو الحال فى ال c# ايضاً

Technical Lead Developer

My LinkedIn Profile

اللهم قنى شر الجهل و الجهلاء

( اقْتَرَبَ لِلنَّاسِ حِسَابُهُمْ وَهُمْ فِي غَفْلَةٍ مَّعْرِضُونَ ) {الأنبياء:1}

#2

اما ان السؤال سهل ولايحتاج لإجابه عليه او ......................

الحمد لله توصلت إلى معرفة الحل هذا النص منقول من ال trainning kit

اقتباس
When creating an array of reference types, declaring and initializing an array does not create an array filled with members of that type. Rather, it creates an array of null references that can point to that type. To fill the array with members, you must assign each variable in the array to an object, which can be either a new object or an existing object. For example:

Visual Basic .NET

' This example creates an array of Widgets, then assigns each variable ' to a Widget objectDim Widgets(10) as Widget' Assigns Widgets(0) to a new Widget object
Widgets(0) = New Widget()' Assigns Widgets(1) to an existing Widget objectDim aWidget As New Widget()Widgets(1) = aWidget' Loops through Widgets and assigns 2 through 10 to a new objectDim Counter as IntegerFor Counter = 2 to 10   Widgets(Counter) = New Widget()Next

Visual C#

// This example creates an array of Widgets, then assigns each
// variable to a Widget object
Widget[] Widgets = new Widget[11];
// Assigns Widgets[0] to a new Widget object
Widgets[0] = new Widget();
// Assigns Widgets[1] to an existing Widget object
Widget aWidget = new Widget();
Widgets[1] = aWidget;
// Loops through Widgets and assigns 2 through 10 to a new object
for (int Counter = 2; Counter < 11; Counter++)
{
Widgets[Counter] = new Widget();
}

تم تعديل هذه المشاركة بواسطة طارق إبراهيم في 10 أبريل 2004 في 06:20

Technical Lead Developer

My LinkedIn Profile

اللهم قنى شر الجهل و الجهلاء

( اقْتَرَبَ لِلنَّاسِ حِسَابُهُمْ وَهُمْ فِي غَفْلَةٍ مَّعْرِضُونَ ) {الأنبياء:1}

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

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

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…