Archive

Archive for กันยายน, 2009

ฟังก์ชั่น หานามสกุลของไฟล์ ด้วยภาษา php

กันยายน 8th, 2009

function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split(”[/\\.]“, $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}

PHP

สร้าง class แบบ dynamic

กันยายน 2nd, 2009
using System;  
using System.Diagnostics;  
class Foo { }  
static class Program  
{  
    static void Main()  
    {  
        Type type = typeof(Foo);  
        const int count = 5000000;
        GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
        RunTestWithActivator(type, count);
        GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
        typeof(Program).GetMethod(“RunTestWithGenerics”).  
            MakeGenericMethod(type).Invoke(nullnew object[] { count });  
    }  
    public static void RunTestWithActivator(Type type, int count)  
    {  
        Stopwatch watch = Stopwatch.StartNew();  
        for (int i = 0; i < count; i++)  
        {  
            object obj = Activator.CreateInstance(type);  
        }  
        watch.Stop();  
        Console.WriteLine(“With Activator: {0}”, watch.ElapsedMilliseconds);  
    }  
    public static void RunTestWithGenerics<T>(int count) where T : new() {  
        Stopwatch watch = Stopwatch.StartNew();  
        for (int i = 0; i < count; i++)  
        {  
            T t = new T();  
        }  
        watch.Stop();  
        Console.WriteLine(“With generics: {0}”, watch.ElapsedMilliseconds);  
    }  

C#