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

كيف أستخدم ال ArrayList ؟

مغلق
بدأه jorhome2 في 1 أبريل 2006 · 5 رد · 795 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

Hi guys

I have array and an ArrayList

string[] stdInfo1 = new string[2];
std={"Ali","Mohammed"};

string[] stdInfo2 = new string[2];
std={"Badr","Saleh"};

ArrayList arL = new ArrayList();
arL.Add(stdInfo1);
arL.Add(stdInfo2);

my qustion is

How to extract the data "array" from the ArrayList?

Thanks

#2

هذا مثال من MSDN لاستخدام ArrayList

using System;
using System.Collections;
public class SamplesArrayList  {

   public static void Main()  {

      // Creates and initializes a new ArrayList.
      ArrayList myAL = new ArrayList();
      myAL.Add("Hello");
      myAL.Add("World");
      myAL.Add("!");

      // Displays the properties and values of the ArrayList.
      Console.WriteLine( "myAL" );
      Console.WriteLine( "    Count:    {0}", myAL.Count );
      Console.WriteLine( "    Capacity: {0}", myAL.Capacity );
      Console.Write( "    Values:" );
      PrintValues( myAL );
   }

   public static void PrintValues( IEnumerable myList )  {
      foreach ( Object obj in myList )
         Console.Write( "   {0}", obj );
      Console.WriteLine();
   }

}
#3

وممكن بدل ما تستخدم الAdd زى ما قال الاخ oldman إستخدم الAddRange Methode اللى الparameter بتاعها من النوع

ICollection يعنى array كما موضح

  string[] a1 = new string[2] { "a", "b" };
            string[] a2 = new string[2] { "c", "d" };
            ArrayList list = new ArrayList();
            list.AddRange(a1);
            
            list.AddRange(a2);
            foreach (string a in list)
                for (int i = 0; i < a.Length; i++)
                    Console.WriteLine("val is {0}", a);

Muhammad Allam

Computer Science

@Resource(MappedURL="My Blog" )

#4

جزاكم الله خير شباب

طيب الان انا بأخذ البينات من ArrayList و بخزنها داخل array

هل هذه الطريقه صحيحه من ناحية الاداء

string[] st1={"Badr ","Mohsen ","Mohammed"};
            string[] st2 ={"Ali ", "Mohsen ", "Mohammed" };
            
            ArrayList myArr = new ArrayList();
            myArr.AddRange(st1);
            myArr.AddRange(st2);
            string[,] record = new string[myArr.Count, 3];
            string word = "";
            int row = 0;
            int column = 0;

            foreach (string name in myArr)
            {
                for (int i = 0; i < name.Length; i++)
                {
                    word += name.ToString();
                }
                record[row, column] = word;
                word = "";
                if (column == 2)
                {
                    row++;
                    column = 0;
                }
                else
                  column++;
            }
#5

أولا المتغير word زيادة وأيضا الfor loop لو حذفتهم البرنامج هيشتغل مية مية (h)

وعندك أيضا دالة أسمها ToArray تستخدم فى إراجاع One Dimensionarray من النوع obect[]

Muhammad Allam

Computer Science

@Resource(MappedURL="My Blog" )

#6

شكراً يا اخي

حذفت الـ word و for loop واشتغل مية مية

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

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