Hasan Akpürüm
Kıdemli Yazılım Danışmanı
Makele Detayı

GetExtension ve EndsWith ile performans farkı

3/6/2011 10:33:35 AM
Çoğu dosya isimleri belirli bir uzantıya sahip. Bazen projelerimizde bir dosya uzantısı için test etmek gerekebilir. Bunun için Path.GetExtension idealdir. Bu yöntem basittir ama özel bir yöntemle performansını karşılaştıracağız.

C #: Path.GetExtension yöntemi

using System; using System.IO;
sınıf Programı { static void Main () { dize p = @"C:\Users\Hasan\Documents\Test.txt";
Dize e = Path.GetExtension (p); if (e == ". txt") { Console.WriteLine (e); } } }

Çıktı

. Txt Burada dosya uzantılarını kontrol etmek için alternatif bir yöntem yapıcaz kendimize. Bu sayede ms bazındada olsa performans olarak işlemimiz fark edecektir.

İpucu: Static yapmamız kullanımı daha net ve işlevi  daha hızlı yapar.

Özel yöntem : C #

using System;
sınıf Programı { static void Main () { dize p = @"C:\Users\Hasan\Documents\Test.txt"; if (IsTxtFile (p)) { Console.WriteLine (". Txt"); } }
static bool IsTxtFile (string f) { dönüş f = null && f.EndsWith (". txt", StringComparison.Ordinal); } }

Çıktı

. Txt

Sonuç

Dosya uzantısı kontrol yöntemi sonuçları

Path.GetExtension:         1322 ms 
Özel IsTxtFile yöntemi:   326 ms [hızlı]

Path.GetExtension:         1296 ms 
Özel IsTxtFile yöntemi:   208 ms [hızlı]
Yorum yaz

Thanks, your message is sent successfully.

cheap air max cheap air jordans pompy wtryskowe cheap nike shoes bombas inyeccion cheap jordans cheap jordan shoes wholesale jordans cheap jordan shoes cheap jordans cheap nike shoes wholesale jordans cheap wholesale jordans cheap wholesale nike cheap wholesale jerseys big size jordans