[Dnsmail-cvs] projeler/sozluk-no/arraylist-hashtable 1.Addrange.cs, NONE, 1.1 10.trimToSize.cs, NON
Brought to you by:
ethem
Update of /cvsroot/dnsmail/projeler/sozluk-no/arraylist-hashtable In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv21812/arraylist-hashtable Added Files: 1.Addrange.cs 10.trimToSize.cs 12.copytoarray.cs 14.copytoarray(Array a,int indeks).cs 15.CopyTo Method (Int32, Array, Int32, Int32).cs 16.Getrange.cs 2.sort.cs 20.removeAt.cs 4.Sort(Icomparer).cs 5.sort(int indeks).cs 6.Binarysearch(object o).cs 7.reverse.cs 8.reverse.cs 9.clear.cs ARRAYLIST SINIFI.doc add.cs arraylist1.cs arraylist2-1.cs arraylist2.cs capacity.cs hashtable.cs hashtablecount.cs Log Message: Sunumdaki kodlar ve metin --- NEW FILE: 16.Getrange.cs --- using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Yeni bir arraylist oluþtururuz ve baþlangýç durumuna getiririz. ArrayList myAL = new ArrayList(); myAL.Add("The"); myAL.Add("quick"); myAL.Add("brown"); myAL.Add("fox"); myAL.Add("jumped"); myAL.Add("over"); myAL.Add("the"); myAL.Add("lazy"); myAL.Add("dog"); //index 0dan baþlatarak 5 tane elemanýn deðerlerini ekrana yazdýrýr. ArrayList mySubAL = myAL.GetRange(0, 5); Console.WriteLine("Index 0 dan 4 kadar arraylistte bulunanlar:"); PrintValues(mySubAL, '\t'); } public static void PrintValues( IEnumerable myList, char mySeparator ) { System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.Write( "{0}{1}", mySeparator, myEnumerator.Current ); Console.WriteLine(); } } /* This code produces the following output. Index 0 through 4 contains: The quick brown fox jumped */ --- NEW FILE: add.cs --- using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Creates and initializes a new ArrayList. ArrayList myAL = new ArrayList(); myAL.Add( "The" ); myAL.Add( "quick" ); myAL.Add( "brown" ); myAL.Add( "fox" ); // Creates and initializes a new Queue. Queue myQueue = new Queue(); myQueue.Enqueue( "jumped" ); myQueue.Enqueue( "over" ); myQueue.Enqueue( "the" ); myQueue.Enqueue( "lazy" ); myQueue.Enqueue( "dog" ); // Displays the ArrayList and the Queue. Console.WriteLine( "The ArrayList initially contains the following:" ); PrintValues( myAL, '\t' ); Console.WriteLine( "The Queue initially contains the following:" ); PrintValues( myQueue, '\t' ); // Copies the Queue elements to the end of the ArrayList. myAL.AddRange( myQueue ); // Displays the ArrayList. Console.WriteLine( "The ArrayList now contains the following:" ); PrintValues( myAL, '\t' ); } public static void PrintValues( IEnumerable myList, char mySeparator ) { System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.Write( "{0}{1}", mySeparator, myEnumerator.Current ); Console.WriteLine(); } } --- NEW FILE: arraylist1.cs --- using System; using system.collections; class Koleksiyon { public static void Main() { ArrayList Alist = new ArrayList(); Console.WriteLine("Varsayýlan Kapasite:" + Alist.Capacity); Alist.Add(6); Alist.Add("CSharp"); Alist.Add('A'); Alist.Add(236.58f); Alist.Add(true); EkranaYaz(Alist); Alist.Remove('A'); Alist(true); Alist("Deneme"); EkranaYaz(Alist); } public static void EkranaYaz(ArrayList al) { foreach (object i in al) Console.Write(i.ToString() + ""); Console.WriteLine(); } } --- NEW FILE: 10.trimToSize.cs --- using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Creates and initializes a new ArrayList. ArrayList myAL = new ArrayList(); myAL.Add( "The" ); myAL.Add( "quick" ); myAL.Add( "brown" ); myAL.Add( "fox" ); myAL.Add( "jumped" ); // Displays the count, capacity and values of the ArrayList. Console.WriteLine( "Initially," ); Console.WriteLine( " Count : {0}", myAL.Count ); Console.WriteLine( " Capacity : {0}", myAL.Capacity ); Console.Write( " Values:" ); PrintValues( myAL ); // Trim the ArrayList. myAL.TrimToSize(); // Displays the count, capacity and values of the ArrayList. Console.WriteLine( "After TrimToSize," ); Console.WriteLine( " Count : {0}", myAL.Count ); Console.WriteLine( " Capacity : {0}", myAL.Capacity ); Console.Write( " Values:" ); PrintValues( myAL ); // Clear the ArrayList. myAL.Clear(); // Displays the count, capacity and values of the ArrayList. Console.WriteLine( "After Clear," ); Console.WriteLine( " Count : {0}", myAL.Count ); Console.WriteLine( " Capacity : {0}", myAL.Capacity ); Console.Write( " Values:" ); PrintValues( myAL ); // Trim the ArrayList again. myAL.TrimToSize(); // Displays the count, capacity and values of the ArrayList. Console.WriteLine( "After the second TrimToSize," ); Console.WriteLine( " Count : {0}", myAL.Count ); Console.WriteLine( " Capacity : {0}", myAL.Capacity ); Console.Write( " Values:" ); PrintValues( myAL ); } public static void PrintValues( IEnumerable myList ) { System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.Write( "\t{0}", myEnumerator.Current ); Console.WriteLine(); } } /* This code produces the following output. Initially, Count : 5 Capacity : 16 Values: The quick brown fox jumped After TrimToSize, Count : 5 Capacity : 5 Values: The quick brown fox jumped After Clear, Count : 0 Capacity : 5 Values: After the second TrimToSize, Count : 0 Capacity : 16 Values: */ --- NEW FILE: 9.clear.cs --- using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Yeni bir arraylist oluþtururuz ve baþlangýç durumuna getiririz. ArrayList myAL = new ArrayList(); myAL.Add( "The" ); myAL.Add( "quick" ); myAL.Add( "brown" ); myAL.Add( "fox" ); myAL.Add( "jumped" ); // ArrayListin elemansayýsýný, kapasitesini ve deðerlerini ekrana yazdýrýrýz. Console.WriteLine( "Initially," ); Console.WriteLine( " Count : {0}", myAL.Count ); Console.WriteLine( " Capacity : {0}", myAL.Capacity ); Console.Write( " Values:" ); PrintValues( myAL ); // ArrayListe Trim özelliði uygulanýr. myAL.TrimToSize(); // ArrayListin elemansayýsýný, kapasitesini ve deðerlerini ekrana yazdýrýrýz. Console.WriteLine( "After TrimToSize," ); Console.WriteLine( " Count : {0}", myAL.Count ); Console.WriteLine( " Capacity : {0}", myAL.Capacity ); Console.Write( " Values:" ); PrintValues( myAL ); // ArrayListin elemanlarý diziden çýkarýlýr. myAL.Clear(); // ArrayListin elemansayýsýný, kapasitesini ve deðerlerini ekrana tekrar yazdýrýrýz. Console.WriteLine( "After Clear," ); Console.WriteLine( " Count : {0}", myAL.Count ); Console.WriteLine( " Capacity : {0}", myAL.Capacity ); Console.Write( " Values:" ); PrintValues( myAL ); // ArrayListe Trim özelliði tekrar uygulanýr. myAL.TrimToSize(); // rrayListin elemansayýsýný, kapasitesini ve deðerlerini ekrana yazdýrýrýz. Console.WriteLine( "After the second TrimToSize," ); Console.WriteLine( " Count : {0}", myAL.Count ); Console.WriteLine( " Capacity : {0}", myAL.Capacity ); Console.Write( " Values:" ); PrintValues( myAL ); } public static void PrintValues( IEnumerable myList ) { System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.Write( "\t{0}", myEnumerator.Current ); Console.WriteLine(); } } /* This code produces the following output. Initially, Count : 5 Capacity : 16 Values: The quick brown fox jumped After TrimToSize, Count : 5 Capacity : 5 Values: The quick brown fox jumped After Clear, Count : 0 Capacity : 5 Values: After the second TrimToSize, Count : 0 Capacity : 16 Values: */ --- NEW FILE: 12.copytoarray.cs --- using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Yeni bir arraylist oluþtururuz ve baþlangýç durumuna getiririz. ArrayList mySourceList = new ArrayList(); mySourceList.Add( "three" ); mySourceList.Add( "napping" ); mySourceList.Add( "cats" ); mySourceList.Add( "in" ); mySourceList.Add( "the" ); mySourceList.Add( "barn" ); // hedef diziye index veririrz. Array myTargetArray=Array.CreateInstance( typeof(String), 15 ); myTargetArray.SetValue( "The", 0 ); myTargetArray.SetValue( "quick", 1 ); myTargetArray.SetValue( "brown", 2 ); myTargetArray.SetValue( "fox", 3 ); myTargetArray.SetValue( "jumped", 4 ); myTargetArray.SetValue( "over", 5 ); myTargetArray.SetValue( "the", 6 ); myTargetArray.SetValue( "lazy", 7 ); myTargetArray.SetValue( "dog", 8 ); // Hedef dizi ekrana önceki haliyle yazdýrýrýz. Console.WriteLine( "Hedef dizi aþaðýdakileri içermektedir:" ); PrintValues( myTargetArray, ' ' ); // Kaynak arraylistin ikinci elemaný hedef diziye 7.indexin yerine kopyalanýr. mySourceList.CopyTo( 1, myTargetArray, 7, 1 ); // Hedef dizinin deðerlerini ekrana yazdýrýrýz. PrintValues( myTargetArray, ' ' ); // Kaynak dizinin baþlangýcýndan itibaren elemanlar hedef dizinin 6.indexinden baþlayarak indexlerin yerine kopyalanýr. mySourceList.CopyTo( myTargetArray, 6 ); // Hedef dizinin deðerlerini ekrana yazdýrýrýz. PrintValues( myTargetArray, ' ' ); // Kaynak dizinin baþlangýcýndan itibaren elemanlar hedef dizinin 0.indexinden baþlayarak kopyalanýr. mySourceList.CopyTo( myTargetArray ); // Hedef dizinin deðerlerini ekrana yazdýrýrýz. PrintValues( myTargetArray, ' ' ); } public static void PrintValues( Array myArr, char mySeparator ) { System.Collections.IEnumerator myEnumerator = myArr.GetEnumerator(); int i = 0; int cols = myArr.GetLength( myArr.Rank - 1 ); while ( myEnumerator.MoveNext() ) { if ( i < cols ) { i++; } else { Console.WriteLine(); i = 1; } Console.Write( "{0}{1}", mySeparator, myEnumerator.Current ); } Console.WriteLine(); } } /* This code produces the following output. The target Array contains the following (before and after copying): The quick brown fox jumped over the lazy dog The quick brown fox jumped over the napping dog The quick brown fox jumped over three napping cats in the barn three napping cats in the barn three napping cats in the barn */ --- NEW FILE: 4.Sort(Icomparer).cs --- using System; using System.Collections; public class SamplesArrayList { public class myReverserClass : IComparer { int IComparer.Compare( Object x, Object y ) { return( (new CaseInsensitiveComparer()).Compare( y, x ) ); } } public static void Main() { // Yeni bir arraylist oluþtururuz ArrayList myAL = new ArrayList(); myAL.Add( "The" ); myAL.Add( "quick" ); myAL.Add( "brown" ); myAL.Add( "fox" ); myAL.Add( "jumps" ); myAL.Add( "over" ); myAL.Add( "the" ); myAL.Add( "lazy" ); myAL.Add( "dog" ); Console.WriteLine( "ArrayList aþaðýdaki deðerleri içermektedir:" ); PrintIndexAndValues( myAL ); myAL.Sort(); Console.WriteLine( "Sort uygulamasýndan:" ); PrintIndexAndValues( myAL ); // IComparer karþýlaþtýrma yöntemine göre ters bir þekilde sýralama iþlemi yapýlýr. IComparer myComparer = new myReverserClass(); myAL.Sort( myComparer ); Console.WriteLine("IComparer karþýlaþtýrma yöntemine göre ters bir þekilde sýralama iþlemi:"); PrintIndexAndValues( myAL ); } public static void PrintIndexAndValues( IEnumerable myList ) { int i = 0; System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.WriteLine( "\t[{0}]:\t{1}", i++, myEnumerator.Current ); Console.WriteLine(); } } /* This code produces the following output. The ArrayList initially contains the following values: [0]: The [1]: quick [2]: brown [3]: fox [4]: jumps [5]: over [6]: the [7]: lazy [8]: dog After sorting with the default comparer: [0]: brown [1]: dog [2]: fox [3]: jumps [4]: lazy [5]: over [6]: quick [7]: the [8]: The After sorting with the reverse case-insensitive comparer: [0]: the [1]: The [2]: quick [3]: over [4]: lazy [5]: jumps [6]: fox [7]: dog [8]: brown */ --- NEW FILE: 14.copytoarray(Array a,int indeks).cs --- using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Creates and initializes the source ArrayList. ArrayList mySourceList = new ArrayList(); mySourceList.Add( "three" ); mySourceList.Add( "napping" ); mySourceList.Add( "cats" ); mySourceList.Add( "in" ); mySourceList.Add( "the" ); mySourceList.Add( "barn" ); // Creates and initializes the one-dimensional target Array. Array myTargetArray=Array.CreateInstance( typeof(String), 15 ); myTargetArray.SetValue( "The", 0 ); myTargetArray.SetValue( "quick", 1 ); myTargetArray.SetValue( "brown", 2 ); myTargetArray.SetValue( "fox", 3 ); myTargetArray.SetValue( "jumped", 4 ); myTargetArray.SetValue( "over", 5 ); myTargetArray.SetValue( "the", 6 ); myTargetArray.SetValue( "lazy", 7 ); myTargetArray.SetValue( "dog", 8 ); // Displays the values of the target Array. Console.WriteLine( "The target Array contains the following (before and after copying):" ); PrintValues( myTargetArray, ' ' ); // Copies the second element from the source ArrayList to the target ArrayList, starting at index 7. mySourceList.CopyTo( 1, myTargetArray, 7, 1 ); // Displays the values of the target Array. PrintValues( myTargetArray, ' ' ); // Copies the entire source ArrayList to the target ArrayList, starting at index 6. mySourceList.CopyTo( myTargetArray, 6 ); // Displays the values of the target Array. PrintValues( myTargetArray, ' ' ); // Copies the entire source ArrayList to the target ArrayList, starting at index 0. mySourceList.CopyTo( myTargetArray ); // Displays the values of the target Array. PrintValues( myTargetArray, ' ' ); } public static void PrintValues( Array myArr, char mySeparator ) { System.Collections.IEnumerator myEnumerator = myArr.GetEnumerator(); int i = 0; int cols = myArr.GetLength( myArr.Rank - 1 ); while ( myEnumerator.MoveNext() ) { if ( i < cols ) { i++; } else { Console.WriteLine(); i = 1; } Console.Write( "{0}{1}", mySeparator, myEnumerator.Current ); } Console.WriteLine(); } } /* This code produces the following output. The target Array contains the following (before and after copying): The quick brown fox jumped over the lazy dog The quick brown fox jumped over the napping dog The quick brown fox jumped over three napping cats in the barn three napping cats in the barn three napping cats in the barn */ --- NEW FILE: hashtablecount.cs --- using System; using System.Collections; class hashtable { public static void Main() { Hashtable sozluk= new Hashtable(); sozluk.Add("Araba","Car"); Sozluk.Add("Masa","Table"); sozluk.Add("Kalem","Pencil"); sozluk["Kitap"]="Book"; sozluk["Bilgisayar"]="Computer"; IDictionaryEnumerator ide = Sozluk.GetENumerator(); while(ide.MoveNext()) Console.Writeline(ide.Key + " = " + ide.Value); Console.Writeline("Toplam Kelime: " + Sozluk.Count); } } --- NEW FILE: 5.sort(int indeks).cs --- using System; using System.Collections; public class SamplesArrayList { public class myReverserClass : IComparer { // Calls CaseInsensitiveComparer.Compare with the parameters reversed. int IComparer.Compare( Object x, Object y ) { return( (new CaseInsensitiveComparer()).Compare( y, x ) ); } } public static void Main() { // Yeni bir arraylist oluþtururuz ArrayList myAL = new ArrayList(); myAL.Add( "The" ); myAL.Add( "QUICK" ); myAL.Add( "BROWN" ); myAL.Add( "FOX" ); myAL.Add( "jumped" ); myAL.Add( "over" ); myAL.Add( "the" ); myAL.Add( "lazy" ); myAL.Add( "dog" ); Console.WriteLine("Alist þu an aþaðýda yazýlanlarý içermektedir."); PrintIndexAndValues( myAL ); // Arraylisti geçerli karþýlaþtýrmaya göre sýralarýz. myAL.Sort( 1, 3, null ); Console.WriteLine( "1.indexten 3.indexe kadar geçerli karþýlaþtýrma özelliðine göre sýralandýktan sonra:" ); PrintIndexAndValues( myAL ); // IComparer karþýlaþtýrma yöntemine göre ters bir þekilde sýralama iþlemi yapýlýr. IComparer myComparer = new myReverserClass(); myAL.Sort( 1, 3, myComparer ); Console.WriteLine("IComparer karþýlaþtýrma yöntemine göre ters bir þekilde sýralama iþlemi:"); PrintIndexAndValues( myAL ); } public static void PrintIndexAndValues( IEnumerable myList ) { int i = 0; System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.WriteLine( "\t[{0}]:\t{1}", i++, myEnumerator.Current ); Console.WriteLine(); } } /* This code produces the following output. The ArrayList initially contains the following values: [0]: The [1]: QUICK [2]: BROWN [3]: FOX [4]: jumped [5]: over [6]: the [7]: lazy [8]: dog After sorting from index 1 to index 3 with the default comparer: [0]: The [1]: BROWN [2]: FOX [3]: QUICK [4]: jumped [5]: over [6]: the [7]: lazy [8]: dog After sorting from index 1 to index 3 with the reverse case-insensitive comparer: [0]: The [1]: QUICK [2]: FOX [3]: BROWN [4]: jumped [5]: over [6]: the [7]: lazy [8]: dog */ --- NEW FILE: 20.removeAt.cs --- using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Yeni bir arraylist oluþtururuz ve baþlangýç durumuna getiririz. ArrayList myAL = new ArrayList(); myAL.Add( "The" ); myAL.Add( "quick" ); myAL.Add( "brown" ); myAL.Add( "fox" ); myAL.Add( "jumped" ); myAL.Add( "over" ); myAL.Add( "the" ); myAL.Add( "lazy" ); myAL.Add( "dog" ); // ArrayListtekileri ekrana yazdýrýrýz. Console.WriteLine("ArrayList aþaðýdaki deðerleri içermektedir:"); PrintValues( myAL ); // "lazy"kelimesini sil. myAL.Remove( "lazy" ); // Þu an ArrayListte bulunan elemanlarý ekrana yazdýrýrýz. Console.WriteLine( " \"lazy\" silindikten sonra:" ); PrintValues( myAL ); // index 5teki elemaný siler. myAL.RemoveAt( 5 ); // Þu an ArrayListte bulunan elemanlarý ekrana yazdýrýrýz. Console.WriteLine( "index 5teki eleman silindikten sonra:" ); PrintValues( myAL ); // index 4ten itibaren 3 eleman sil. myAL.RemoveRange( 4, 3 ); // Þu an ArrayListte bulunan elemanlarý ekrana yazdýrýrýz. Console.WriteLine("index 4ten itibaren 3 eleman silindikten sonra:"); PrintValues( myAL ); } public static void PrintValues( IEnumerable myList ) { System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.Write( "\t{0}", myEnumerator.Current ); Console.WriteLine(); } } /* This code produces the following output. The ArrayList initially contains the following: The quick brown fox jumped over the lazy dog After removing "lazy": The quick brown fox jumped over the dog After removing the element at index 5: The quick brown fox jumped the dog After removing three elements starting at index 4: The quick brown fox */ --- NEW FILE: arraylist2-1.cs --- using System; using system.collections; class Deneme { int x; public Deneme(int x) { this.x = x; } } class Koleksiyon { public static void Main() { Arraylist Alist = new Arraylist(); Alist.Add("Sefer"); Alist.Add("Algan"); Alist.Add("Gökçen"); Alist.Add("Yýldýrým"); Deneme d = new Deneme(5); Alist.Add(d); ArrayList Alist = ArrayList.FixedSize(ArrayList (Alist)); foreach(object i in Alist) Console.WriteLine((string)i); } } --- NEW FILE: 8.reverse.cs --- using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Yeni bir arraylist oluþtururuz ve baþlangýç durumuna getiririz. ArrayList myAL = new ArrayList(); myAL.Add( "The" ); myAL.Add( "QUICK" ); myAL.Add( "BROWN" ); myAL.Add( "FOX" ); myAL.Add( "jumps" ); myAL.Add( "over" ); myAL.Add( "the" ); myAL.Add( "lazy" ); myAL.Add( "dog" ); // ArrayListteki deðerleri ekrana yazdýrýrýz. Console.WriteLine("ArrayList aþaðýdaki deðerleri içermektedir::"); PrintIndexAndValues( myAL ); // ArrayListtekileri index deðerlerine göre ters çevirip sýralarýz. myAL.Reverse( 1, 3 ); // ArrayListteki deðerleri ekrana yazdýrýrýz. Console.WriteLine( "Çevirme iþleminden sonra:" ); PrintIndexAndValues( myAL ); } public static void PrintIndexAndValues( IEnumerable myList ) { int i = 0; System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.WriteLine( "\t[{0}]:\t{1}", i++, myEnumerator.Current ); Console.WriteLine(); } } /* This code produces the following output. The ArrayList initially contains the following values: [0]: The [1]: QUICK [2]: BROWN [3]: FOX [4]: jumps [5]: over [6]: the [7]: lazy [8]: dog After reversing: [0]: The [1]: FOX [2]: BROWN [3]: QUICK [4]: jumps [5]: over [6]: the [7]: lazy [8]: dog */ --- NEW FILE: hashtable.cs --- using System; using System.Collections; class hashtable { public static void Main() { Hashtable sozluk= new Hashtable(); sozluk.Add("Araba","Car"); Sozluk.Add("Masa","Table"); sozluk.Add("Kalem","Pencil"); sozluk["Kitap"]="Book"; sozluk["Bilgisayar"]="Computer"; ICollection anahtarlar = Sozluk.Keys; foreach(string anahtar in anahtarlar) Console.Writeline(anahtar + " = " + sozluk[anahtar]); Console.WriteLine("Toplam Kelime: "+ Sozluk.Count); } } --- NEW FILE: 7.reverse.cs --- using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Yeni bir arraylist oluþtururuz ve baþlangýç durumuna getiririz. ArrayList myAL = new ArrayList(); myAL.Add( "The" ); myAL.Add( "quick" ); myAL.Add( "brown" ); myAL.Add( "fox" ); myAL.Add( "jumps" ); myAL.Add( "over" ); myAL.Add( "the" ); myAL.Add( "lazy" ); myAL.Add( "dog" ); // ArrayListteki deðerleri ekrana yazdýrýrýz. Console.WriteLine("ArrayList aþaðýdaki deðerleri içermektedir:"); PrintIndexAndValues( myAL ); // ArrayListtekileri deðerlerine göre ters çevirip sýralarýz. myAL.Reverse(); // ArrayListteki deðerleri ekrana yazdýrýrýz. Console.WriteLine( "Çevirme iþlemi yapýldýktan sonra:" ); PrintIndexAndValues( myAL ); } public static void PrintIndexAndValues( IEnumerable myList ) { int i = 0; System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.WriteLine( "\t[{0}]:\t{1}", i++, myEnumerator.Current ); Console.WriteLine(); } } /* This code produces the following output. The ArrayList initially contains the following values: [0]: The [1]: quick [2]: brown [3]: fox [4]: jumps [5]: over [6]: the [7]: lazy [8]: dog After reversing: [0]: dog [1]: lazy [2]: the [3]: over [4]: jumps [5]: fox [6]: brown [7]: quick [8]: The */ --- NEW FILE: 15.CopyTo Method (Int32, Array, Int32, Int32).cs --- using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Creates and initializes the source ArrayList. ArrayList mySourceList = new ArrayList(); mySourceList.Add( "three" ); mySourceList.Add( "napping" ); mySourceList.Add( "cats" ); mySourceList.Add( "in" ); mySourceList.Add( "the" ); mySourceList.Add( "barn" ); // Creates and initializes the one-dimensional target Array. Array myTargetArray=Array.CreateInstance( typeof(String), 15 ); myTargetArray.SetValue( "The", 0 ); myTargetArray.SetValue( "quick", 1 ); myTargetArray.SetValue( "brown", 2 ); myTargetArray.SetValue( "fox", 3 ); myTargetArray.SetValue( "jumped", 4 ); myTargetArray.SetValue( "over", 5 ); myTargetArray.SetValue( "the", 6 ); myTargetArray.SetValue( "lazy", 7 ); myTargetArray.SetValue( "dog", 8 ); // Displays the values of the target Array. Console.WriteLine( "The target Array contains the following (before and after copying):" ); PrintValues( myTargetArray, ' ' ); // Copies the second element from the source ArrayList to the target ArrayList, starting at index 7. mySourceList.CopyTo( 1, myTargetArray, 7, 1 ); // Displays the values of the target Array. PrintValues( myTargetArray, ' ' ); // Copies the entire source ArrayList to the target ArrayList, starting at index 6. mySourceList.CopyTo( myTargetArray, 6 ); // Displays the values of the target Array. PrintValues( myTargetArray, ' ' ); // Copies the entire source ArrayList to the target ArrayList, starting at index 0. mySourceList.CopyTo( myTargetArray ); // Displays the values of the target Array. PrintValues( myTargetArray, ' ' ); } public static void PrintValues( Array myArr, char mySeparator ) { System.Collections.IEnumerator myEnumerator = myArr.GetEnumerator(); int i = 0; int cols = myArr.GetLength( myArr.Rank - 1 ); while ( myEnumerator.MoveNext() ) { if ( i < cols ) { i++; } else { Console.WriteLine(); i = 1; } Console.Write( "{0}{1}", mySeparator, myEnumerator.Current ); } Console.WriteLine(); } } /* This code produces the following output. The target Array contains the following (before and after copying): The quick brown fox jumped over the lazy dog The quick brown fox jumped over the napping dog The quick brown fox jumped over three napping cats in the barn three napping cats in the barn three napping cats in the barn */ --- NEW FILE: arraylist2.cs --- using System; using system.collections; class Deneme { int x; public Deneme(int x) { this.x = x; } } class Koleksiyon { public static void Main() { Arraylist Alist = new Arraylist(); Alist.Add("Sefer"); Alist.Add("Algan"); Alist.Add("Gökçen"); Alist.Add("Yýldýrým"); Deneme d new Deneme(5); Alist.Add(d); foreach(object i in Alist) Console.WriteLine((string)i); } } --- NEW FILE: 2.sort.cs --- using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Yeni bir arraylist oluþtururuz. ArrayList myAL = new ArrayList(); myAL.Add( "The" ); myAL.Add( "quick" ); myAL.Add( "brown" ); myAL.Add( "fox" ); myAL.Add( "jumps" ); myAL.Add( "over" ); myAL.Add( "the" ); myAL.Add( "lazy" ); myAL.Add( "dog" ); //ArrayListteki deðerler göstermek için. Console.WriteLine("Alist þu an aþaðýda yazýlanlarý içermektedir."); PrintIndexAndValues( myAL ); // ArrayListtekileri sýralar. myAL.Sort(); // ArrayListteki deðerleri göstermek için. Console.WriteLine( "Sýralamanýn ardýndan:" ); PrintIndexAndValues( myAL ); } public static void PrintIndexAndValues( IEnumerable myList ) { int i = 0; System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.WriteLine( "\t[{0}]:\t{1}", i++, myEnumerator.Current ); Console.WriteLine(); } } /* This code produces the following output. The ArrayList initially contains the following values: [0]: The [1]: quick [2]: brown [3]: fox [4]: jumps [5]: over [6]: the [7]: lazy [8]: dog After sorting: [0]: brown [1]: dog [2]: fox [3]: jumps [4]: lazy [5]: over [6]: quick [7]: the [8]: The */ --- NEW FILE: 1.Addrange.cs --- using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Yeni bir arraylist oluþtururuz. ArrayList alist = new ArrayList(); alist.Add( "The" ); alist.Add( "quick" ); alist.Add( "brown" ); alist.Add( "fox" ); // oluþturulmuþ Alistin arkasýna ekleyeceðimiz cümleyi yazarýz. Queue listearkasi = new Queue(); listearkasi.Enqueue( "jumped" ); listearkasi.Enqueue( "over" ); listearkasi.Enqueue( "the" ); listearkasi.Enqueue( "lazy" ); listearkasi.Enqueue( "dog" ); Console.WriteLine( "Arraylist:" ); PrintValues( alist, '\t' ); Console.WriteLine( "Listearkasý" ); PrintValues( listearkasi, '\t' ); // Daha sonradan oluþturulmuþ cümleyi alist'in sonuna kopyalarýz. alist.AddRange( listearkasi ); // Console.WriteLine( "Alist þu an aþaðýda yazýlanlarý içermektedir." ); PrintValues( alist, '\t' ); } public static void PrintValues( IEnumerable myList, char mySeparator ) { System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.Write( "{0}{1}", mySeparator, myEnumerator.Current ); Console.WriteLine(); } } /* Kodun ekran çýktýsý. AList aþaðýdakileri içermektedir.: The quick brown fox Queue aþaðýdakileri içermektedir.: jumped over the lazy dog AList þu an aþaðýdakileri içermektedir.: The quick brown fox jumped over the lazy dog */ --- NEW FILE: capacity.cs --- using system; using system.collections; class Koleksiyon { public static void Main() { Arraylist Alist= new ArrayList(2); Alist.Add(1); Alist.Add(2); Alist.Add(3); Alist.Add(4); Alist.Add(5); Console.writeline(Alist.Capacity); } } --- NEW FILE: ARRAYLIST SINIFI.doc --- (This appears to be a binary file; contents omitted.) --- NEW FILE: 6.Binarysearch(object o).cs --- using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Yeni bir arraylist oluþtururuz ve baþlangýç durumuna getiririz. ArrayList myAL = new ArrayList(); for ( int i = 0; i <= 4; i++ ) myAL.Add( i*2 ); // Arraylistin ilk durumunu gösterir. Console.WriteLine( "The Int32 ArrayList aþaðýdakileri gösterir:" ); PrintValues( myAL ); // Arraylistte olmayan bir eleman aratýrýz. Object myObjectOdd = 3; FindMyObject( myAL, myObjectOdd ); //ArrayListte bulunan bir nesne aratýrýz. Object myObjectEven = 6; FindMyObject( myAL, myObjectEven ); } public static void FindMyObject( ArrayList myList, Object myObject ) { int myIndex=myList.BinarySearch( myObject ); if ( myIndex < 0 ) Console.WriteLine( "Aratýlan eleman ({0}) bulunamadý.en yakýn index {1}.", myObject, ~myIndex ); else Console.WriteLine("Aratýlan eleman ({0}) index {1} de.", myObject, myIndex); } public static void PrintValues( IEnumerable myList ) { System.Collections.IEnumerator myEnumerator = myList.GetEnumerator(); while ( myEnumerator.MoveNext() ) Console.Write( "\t{0}", myEnumerator.Current ); Console.WriteLine(); } } /* This code produces the following output. The Int32 ArrayList contains the following: 0 2 4 6 8 The object to search for (3) is not found. The next larger object is at index 2. The object to search for (6) is at index 3. */ |