IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası

IRCForumları - IRC ve mIRC Kullanıcılarının Buluşma Noktası (https://www.ircforumlari.net/)
-   C# (https://www.ircforumlari.net/c/)
-   -   Dizideki tekrarlanan elemanları silme (https://www.ircforumlari.net/c/124399-dizideki-tekrarlanan-elemanlari-silme.html)

Cemalizim 19 Temmuz 2008 15:54

Dizideki tekrarlanan elemanları silme
 
Array içindeki tekrarlanan elemanları .Net 1.1'de bulunan System.Array sınıfı ile temizler


PHP- Kodu:

// Fonksiyon Kodları
public static Array DeleteDuplicates(Array arr)
{
   
// this procedure works only with vectors
   
if (arr.Rank != )
      throw new 
ArgumentException("Multiple-dimension arrays are not supported");

   
// we use a hashtable to track duplicates
   // make the hash table large enough to avoid memory re-allocations
   
Hashtable ht = new Hashtable(arr.Length 2);
   
// we will store unique elements in this ArrayList
   
ArrayList elements = new ArrayList();

   foreach (
object Value in arr)
   {
      if ( !
ht.Contains(Value) )
      {
         
// we've found a non duplicate
         
elements.Add(Value);
         
// remember it for later
         
ht.Add(Valuenull);
      }
   }
   
// return an array of same type as the original array
   
return elements.ToArray(arr.GetType().GetElementType());
}

// Örnek Kullanım:
int[] numbers = new int[] {1352314};
int[] result = (int[]) DropDuplicates(numbers);
foreach (
int num in result)
   
Console.WriteLine(num); 

Alıntıdır


Tüm Zamanlar GMT +3 Olarak Ayarlanmış. Şuanki Zaman: 11:54.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO
Copyright ©2004 - 2025 IRCForumlari.Net Sparhawk