<?xml version="1.0" encoding="UTF-8" ?> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Programming Collection</title><link>http://blogs.wankuma.com/hirase/category/1665.aspx</link><description>Programming Collection</description><managingEditor>T.Hirase</managingEditor><dc:language>ja-JP</dc:language><generator>.Text Version 0.95.2004.102</generator><item><dc:creator>T.Hirase</dc:creator><title>[HTML/CSS] もっとシンプルに定義リストdt ddを横並び</title><link>http://blogs.wankuma.com/hirase/archive/2008/07/19/149672.aspx</link><pubDate>Sat, 19 Jul 2008 00:28:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/07/19/149672.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/149672.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/07/19/149672.aspx#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/149672.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/149672.aspx</trackback:ping><description>&lt;p&gt;HTMLとCSSだけで、定義リスト（dt/dd）を横並びに表示するのは、結構面倒です。&lt;/p&gt;
&lt;p&gt;定義（dd）の方が固定長である必要があったりします。&lt;/p&gt;
&lt;p&gt;そんなこんなで、CSS2から追加された「display: table」を使ったシンプルな横並びの方法を実現してみました。&lt;/p&gt;
&lt;p&gt;&lt;ins&gt;下記のコードを参照される際は、必ずコメント欄もご参照ください。&lt;/ins&gt;&lt;/p&gt;
&lt;pre class="html" xml:space="preserve" name="sourceCode"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; ?&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Strict//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&amp;quot;&amp;gt;
&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot; lang=&amp;quot;ja&amp;quot; xml:lang=&amp;quot;ja&amp;quot;&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Simple Definition List&amp;lt;/title&amp;gt;
    &amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt;
	dl        { display: table; }
	dl dt.row { display: table-row; }
	dl dt     { display: table-cell; padding-right: 0.4em; }
	dl dd     { display: table-cell; }
	&amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;dl&amp;gt;
        &amp;lt;dt class=&amp;quot;row&amp;quot; /&amp;gt;
        &amp;lt;dt&amp;gt;要勤務日数&amp;lt;/dt&amp;gt;&amp;lt;dd&amp;gt;20日&amp;lt;/dd&amp;gt;
        &amp;lt;dt class=&amp;quot;row&amp;quot; /&amp;gt;
        &amp;lt;dt&amp;gt;勤務時間&amp;lt;/dt&amp;gt;&amp;lt;dd&amp;gt;480時間&amp;lt;/dd&amp;gt;
    &amp;lt;/dl&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;
&lt;p&gt;対応ブラウザは、IE8、Firefox3、Saferi3 です。たぶん、Opera も行けます。&lt;/p&gt;
&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/149672.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C#] Google Protocol Buffers Serializer</title><link>http://blogs.wankuma.com/hirase/archive/2008/07/09/148170.aspx</link><pubDate>Wed, 09 Jul 2008 16:10:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/07/09/148170.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/148170.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/07/09/148170.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/148170.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/148170.aspx</trackback:ping><description>&lt;p&gt;&lt;a href="http://code.google.com/apis/protocolbuffers/"&gt;Google Protocol Buffers&lt;/a&gt;が公開されたとのことで、C#版のシリアライザ（仕様の確認はまた今度）を作ってみました。&lt;/p&gt;
&lt;pre class="csharp" xml:space="preserve" name="sourceCode"&gt;
namespace ProtocolBuffers
{
    using System;
    using System.IO;
    using System.Text;

    public class Serializer
    {
        #region Serialize
        public static void Serialize&amp;lt;TSerialize&amp;gt;(StreamWriter writer, TSerialize instance)
        {
            SerializeInternal(writer, instance.GetType(), instance, 0);
        }

        public static void Serialize(StreamWriter writer, Type type, Object instance)
        {
            SerializeInternal(writer, type, instance, 0);
        }

        private static void SerializeInternal(StreamWriter writer, Type type, Object instance, Int32 depth)
        {
            if (writer == null) throw new System.ArgumentNullException(&amp;quot;writer&amp;quot;);
            if (type == null) throw new System.ArgumentNullException(&amp;quot;type&amp;quot;);
            if (instance == null) throw new System.ArgumentNullException(&amp;quot;instance&amp;quot;);

            WriteIndent(writer, depth);
            writer.Write(type.Name);
            writer.WriteLine(&amp;quot;{&amp;quot;);
            foreach (var propertyInfo in type.GetProperties())
            {
                if (!propertyInfo.CanRead) continue;

                var propertyType = propertyInfo.PropertyType;
                var propertyName = propertyInfo.Name;
                var propertyValue = propertyInfo.GetValue(instance, null) ?? String.Empty;
                if (IsSystemType(propertyType))
                {
                    WriteIndent(writer, depth + 1);
                    writer.WriteLine(&amp;quot;{0} : \&amp;quot;{1}\&amp;quot;&amp;quot;, propertyName, propertyValue.ToString().Replace(&amp;quot;\&amp;quot;&amp;quot;, &amp;quot;\\\&amp;quot;&amp;quot;));
                }
                else
                {
                    SerializeInternal(writer, propertyType, propertyValue, depth + 1);
                }
            }
            WriteIndent(writer, depth);
            writer.WriteLine(&amp;quot;}&amp;quot;);
        }
        private static void WriteIndent(StreamWriter writer, Int32 depth)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(' ', depth);
            writer.Write(sb.ToString());
        }
        #endregion
        #region Utility
        private static Boolean IsSystemType(Type type)
        {
            return type.Namespace.StartsWith(&amp;quot;System&amp;quot;);
        }
        #endregion
    }
}
&lt;/pre&gt;
&lt;p&gt;使い方は、以下&lt;/p&gt;
&lt;pre class="csharp" xml:space="preserve" name="sourceCode"&gt;
namespace ProtocolBuffers
{
    using System;
    using System.IO;

    public class Test
    {
        public String Name { get; set; }
        public String EMail { get; set; }
    }

    public class Test2
    {
        public Test Test { get; set; }
        public Int32 Hash { get { return this.GetHashCode(); } }
        public DateTime DateTime { get { return DateTime.Now; } }
    }

    class TestProgram
    {
        static void Main(string[] args)
        {
            var testObject = new Test { Name = "Hirase", EMail = "hirase@example.com" };
            var test2Object = new Test2 { Test = testObject };
            using (var writer = new StreamWriter(@"test.pb"))
            {
                Serializer.Serialize&amp;lt;Test2&amp;gt;(writer, test2Object);
            }
        }
    }
}
&lt;/pre&gt;
&lt;p&gt;結果は以下&lt;/p&gt;
&lt;pre&gt;
Test2{
 Test{
  Name : &amp;quot;Hirase&amp;quot;
  EMail : &amp;quot;hirase@example.com&amp;quot;
 }
 Hash : &amp;quot;54267293&amp;quot;
 DateTime : &amp;quot;2008/07/09 14:37:08&amp;quot;
}
&lt;/pre&gt;
&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/148170.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C++/CLI] アンマネージのコールバックにマネージのメソッドを登録する。</title><link>http://blogs.wankuma.com/hirase/archive/2008/06/09/142430.aspx</link><pubDate>Mon, 09 Jun 2008 21:34:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/06/09/142430.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/142430.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/06/09/142430.aspx#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/142430.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/142430.aspx</trackback:ping><description>&lt;p&gt;こんな方法は・・・・・・・&lt;/p&gt;
&lt;pre class="cpp" xml:space="preserve" name="sourceCode"&gt;using namespace System;

#pragma unmanaged
// コールバック関数の型
typedef int (__stdcall *CallbackFuncType)(int, float);

// コールバック関数
static CallbackFuncType g_func;

// コールバック関数の登録
void SetCallback(CallbackFuncType f)
{
    g_func = f;
}

// コールバック関数の呼び出し。
int Run()
{
    return g_func(10, 0.5f);
}
#pragma managed

int __stdcall MyFunc(int i, float f)
{
    Console::WriteLine(i.ToString());
    return static_cast&amp;lt;int&amp;gt;(i * f);
}

int main(array&amp;lt;System::String ^&amp;gt; ^args)
{
    // Callback登録（マネージ関数を登録・・）
    SetCallback(MyFunc);

    // GCしても大丈夫かを確認（登録した関数ポインタがGCされる・・ない）
    GC::Collect(2, GCCollectionMode::Forced);

    // コールバックをネイティブ関数に呼び出してもらう（GCされてたら死亡）
    Int32 ret = Run();
    Console::WriteLine(ret.ToString());

    return 0;
}
&lt;/pre&gt;
&lt;p&gt;これって、どうなんだろう。実行は問題ないんだけど。。&lt;/p&gt;
&lt;p&gt;MSDN「&lt;a href="http://msdn.microsoft.com/library/367eeye0.aspx"&gt;方法 : C++ Interop を使用してコールバックおよびデリゲートをマーシャリングする&lt;/a&gt;」とは違う方法で、&lt;a href="http://msdn.microsoft.com/library/system.runtime.interopservices.marshal.getfunctionpointerfordelegate.aspx"&gt;Marshal::GetFunctionPointerForDelegate()&lt;/a&gt; も使わないんだけど・・・。&lt;/p&gt;
&lt;p&gt;何かご存じの方、、ヘルプミー。&lt;/p&gt;
&lt;h3&gt;See Also&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?topic=36275&amp;forum=7"&gt;[C#] デリゲートをGCの対象から外す方法&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/ja-JP/library/367eeye0.aspx"&gt;方法 : C++ Interop を使用してコールバックおよびデリゲートをマーシャリングする&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/367eeye0.aspx"&gt;How to: Marshal Callbacks and Delegates Using C++ Interop&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/142430.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C] wchar_tって・・・。</title><link>http://blogs.wankuma.com/hirase/archive/2008/05/27/139688.aspx</link><pubDate>Tue, 27 May 2008 22:37:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/05/27/139688.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/139688.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/05/27/139688.aspx#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/139688.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/139688.aspx</trackback:ping><description>&lt;p&gt;VC2008で、ソースファイルのプロパティで&lt;br&gt;
「詳細」の「コンパイル言語の選択」を「Cコードとしてコンパイル (/TC)」として、&lt;br&gt;
「言語」の「wchar_t をビルトイン型として扱う (/Zc:wchar_t」を「はい」にすると、&lt;br&gt;
wchar_t が組み込み型として使えそうなのに、使えないんですね・・・。&lt;br&gt;
&lt;br&gt;
# wchar.hをincludeすれば使えますけど、unsigned short扱いだし、&lt;br&gt;
# CRTを使いたくないのに、wchar.h から crtdefs.h を読み込んじゃうし・・・&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
C で書くなと？？&lt;br&gt;
&lt;/p&gt;&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/139688.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C++] シェーカーソート</title><link>http://blogs.wankuma.com/hirase/archive/2008/05/08/136788.aspx</link><pubDate>Thu, 08 May 2008 02:33:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/05/08/136788.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/136788.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/05/08/136788.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/136788.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/136788.aspx</trackback:ping><description>&lt;h2&gt;シェーカーソート（シェーカーソート、Shaker sort、カクテルソート、Cocktail sort、双方向バブルソート、bidirectional bubble sort）。&lt;/h2&gt;
&lt;p&gt;バブルソートの改良版。バブルソートで1回のループで昇順と降順を一度に並び替える。同じ要素の並びは変わらない安定ソート。&lt;/p&gt;
&lt;pre class="cpp" xml:space="preserve" name="sourceCode"&gt;template &amp;lt;typename TElement, typename TSize&amp;gt;
void ShakerSort(TElement * data, const TSize size)
{
    TSize head = 0;
    TSize tail = size - 1;
    while (head &amp;lt; tail)
    {
        TSize swapPos = head;

        for (TSize i = head; i &amp;lt; tail; ++i)
        {
            TElement diff = data[i] - data[i+1];
            if (diff &amp;gt; 0)
            {
                data[i  ] = data[i+1];
                data[i+1] = diff + data[i];
                swapPos = i;
            }
        }

        tail = swapPos;

        for (TSize i = tail; i &amp;gt; head; --i)
        {
            TElement diff = data[i] - data[i+1];
            if (diff &amp;gt; 0)
            {
                data[i  ] = data[i+1];
                data[i+1] = diff + data[i];
                swapPos = i;
            }
        }
        {    // TSizeがunsigned型の場合、対策。
            TSize i = head;
            TElement diff = data[i] - data[i+1];
            if (diff &amp;gt; 0)
            {
                data[i  ] = data[i+1];
                data[i+1] = diff + data[i];
                swapPos = i;
            }
        }
        head = swapPos;
    }
}
&lt;/pre&gt;&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/136788.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C++] ハトの巣ソート</title><link>http://blogs.wankuma.com/hirase/archive/2008/05/08/136781.aspx</link><pubDate>Thu, 08 May 2008 01:37:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/05/08/136781.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/136781.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/05/08/136781.aspx#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/136781.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/136781.aspx</trackback:ping><description>&lt;h2&gt;ハトの巣ソート（ピジョンソート、Pigeon sort）。&lt;/h2&gt;
&lt;p&gt;いまいち理解できていないので、Wikipedia様に丸投げ→→「&lt;a href="http://en.wikipedia.org/wiki/Pigeonhole_sort" target="_blank"&gt;Pigeonhole sort&lt;/a&gt;」。（ 18:06, 19 March 2008版には擬似コードもあり。）&lt;/p&gt;
&lt;p&gt;メモリは食うけど、ソートは馬鹿早い。同じ要素の並びは変わらない安定ソート。&lt;/p&gt;
&lt;p&gt;追記＠2008-05-12T23:39+09:00：新しいバージョンをアップ。&lt;/p&gt;
&lt;pre class="cpp" xml:space="preserve" name="sourceCode"&gt;/* データはユニークである必要があります。 */
template&amp;lt;typename TElement, typename TSize&amp;gt;
void PigeonholeSort(TElement * data, const TSize size)
{
    TElement min = data[0];
    TElement max = min;
    for (TSize i = 1; i &amp;lt; size; ++i) {
        min = data[i] &amp;lt; min ? data[i] : min;
        max = data[i] &amp;gt; max ? data[i] : max;
    }

    TSize range = max - min + 1;
    TElement * pigeonholes = new TElement[range];
    for (TSize i = 0; i &amp;lt; range; ++i)
        pigeonholes[i] = 0;	/* memsetで十分。 */

    for (TSize i = 0; i &amp;lt; size; ++i)
        pigeonholes[data[i]-min] = data[i];

    TSize dataPos = 0;
    for (TSize i = 0; i &amp;lt; range; ++i)
        if (pigeonholes[i] != 0)
            data[dataPos++] = i + min;

    delete[] pigeonholes;
}&lt;/pre&gt;
&lt;p&gt;追記@2008-05-08T17:19+09:00：下記のコードはちょっと間違えています。そのうち修正しますので、くれぐれも参考にしないよう、お願いします。&lt;/p&gt;
&lt;pre class="cpp" xml:space="preserve" name="sourceCode"&gt;#include &amp;lt;map&amp;gt;
 
template&amp;lt;typename TElement, typename TSize&amp;gt;
void PigeonholeSort(TElement * data, const TSize size)
{
    typedef std::map&amp;lt;TElement, std::vector&amp;lt;TElement&amp;gt; &amp;gt; TMap;
    TMap pigeonholes;
    
    for (TSize i = 0; i &amp;lt; size; ++i)
        pigeonholes[data[i]].push_back(data[i]);
    
    TSize dataPos = 0;
    const TMap::const_iterator end = pigeonholes.end();
    for (TMap::iterator it = pigeonholes.begin(); it != end; ++it)
    {
        const TMap::value_type &amp; pigeonhole = *it;
        const TSize size =  pigeonhole.second.size();
        for (TSize i = 0; i &amp;lt; size; ++i)
        {
            data[dataPos++] = pigeonhole.first;
        }
    }
}
&lt;/pre&gt;&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/136781.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C++] 選択ソート</title><link>http://blogs.wankuma.com/hirase/archive/2008/05/08/136763.aspx</link><pubDate>Thu, 08 May 2008 00:18:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/05/08/136763.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/136763.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/05/08/136763.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/136763.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/136763.aspx</trackback:ping><description>&lt;h2&gt;選択ソート（直接選択ソート、Selection sort）。&lt;/h2&gt;
&lt;p&gt;一番小さいのを選んで、先頭へ。次に小さいのを選んで2番目に・・・と並べる。一般的には、同じ要素の並びが変わってしまう不安定ソート。&lt;/p&gt;
&lt;pre class="cpp" xml:space="preserve" name="sourceCode"&gt;template&amp;lt;typename TElement, typename TSize&amp;gt;
void SelectionSort(TElement * data, const TSize size)
{
    TSize tail = size - 1;
    for (TSize head = 0; head &amp;lt; tail; ++head)
    {
        TElement * pMin = (data + head);
        for (TSize pos = head + 1; pos &amp;lt; size; ++pos)
            if (data[pos] &amp;lt; *pMin) pMin = (data + pos);
    
        if (data + head != pMin)
        {
            TElement temp = data[head];
            data[head] = *pMin;
            *pMin = temp;
        }
    }
}
&lt;/pre&gt;&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/136763.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C++] バブルソート</title><link>http://blogs.wankuma.com/hirase/archive/2008/05/07/136743.aspx</link><pubDate>Wed, 07 May 2008 23:34:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/05/07/136743.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/136743.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/05/07/136743.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/136743.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/136743.aspx</trackback:ping><description>&lt;h2&gt;バブルソート（Bubble sort）&lt;/h2&gt;
&lt;p&gt;2つの要素を比べては交換、比べては交換して、交換できる要素がなくなれば終了。同じ要素の並びは変わらない安定ソート。&lt;/p&gt;
&lt;pre class="cpp" xml:space="preserve" name="sourceCode"&gt;template &amp;lt;typename TElement, typename TSize&amp;gt;
void BubbleSort(TElement * data, const TSize size)
{
    bool swapped = false;
    do
    {
        swapped = false;
        const TSize max = size - 1;
        for (TSize i = 0; i &amp;lt; max; ++i)
        {
            TElement diff = data[i] - data[i+1];
            if (diff &amp;gt; 0)
            {
                data[i  ] = data[i+1];
                data[i+1] = diff + data[i];
                swapped = true;
            }
        }
    } while (swapped);
}
&lt;/pre&gt;
&lt;p&gt;これでOK？&lt;/p&gt;
&lt;p&gt;交換するコードが、味噌味。&lt;/p&gt;&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/136743.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C#] String文字列からLinq実行</title><link>http://blogs.wankuma.com/hirase/archive/2008/04/08/132255.aspx</link><pubDate>Tue, 08 Apr 2008 18:17:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/04/08/132255.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/132255.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/04/08/132255.aspx#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/132255.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/132255.aspx</trackback:ping><description>&lt;p&gt;Regexのテスターみたいに、Linqのテスターを作ろうと思ったら、StringからLinqする術がわからなかった。&lt;/p&gt;
&lt;p&gt;ので、ゴリゴリ手書き。もっと良い方法があればフィードバックプリーズ。&lt;/p&gt;
&lt;pre class="csharp" xml:space="preserve" name="sourceCode"&gt;using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using Microsoft.CSharp;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("====== String文字列からLinq実行。 ======");

        // パート1
        var data1 = new Int32[] { 10, 11, 14, 18, 19, 21, 22, 28 };
        Console.Write("データ1: ");
        foreach (var value in data1) Console.Write(value + ",");
        Console.WriteLine();
        var res1 = LinqFrom&amp;lt;Int32&amp;gt;("from v in data where predicater(v) select v;"
            , "TempNamespace", "TempClass", "TempFunc"
            , data1, delegate(Int32 v) { return v % 2 == 0; });
        Console.Write("データ1の偶数要素： ");
        foreach (var value in res1) Console.Write(value + ",");
        Console.WriteLine();
        Console.WriteLine();

        // パート2
        var data2 = new String[] { "RedHat", "Fedora", "Mac", "Windows XP", "Windows Vista" };
        Console.Write("データ2: ");
        foreach (var value in data2) Console.Write(value + ",");
        Console.WriteLine();
        var res2 = LinqFrom&amp;lt;String&amp;gt;("from v in data where predicater(v) select v;"
            , "TempNamespace", "TempClass", "TempFunc"
            , data2, delegate(String v) { return v.StartsWith("Windows"); });
        Console.Write("データ2のWindows： ");
        foreach (var value in res2) Console.Write(value + ",");
        Console.WriteLine();
    }

    public static IEnumerable&amp;lt;T&amp;gt; LinqFrom&amp;lt;T&amp;gt;(String linqText, String tempNamespace, String tempClassName, String tempFuncName, IEnumerable&amp;lt;T&amp;gt; data, Predicate&amp;lt;T&amp;gt; predicater)
    {
        CodeDomProvider provider = new CSharpCodeProvider(new Dictionary&amp;lt;string, string&amp;gt;() { { "CompilerVersion", "v3.5" } });
        CompilerParameters cp = new CompilerParameters();
        cp.GenerateInMemory = true;
        cp.ReferencedAssemblies.Add("System.Core.dll");
        cp.ReferencedAssemblies.Add("System.Xml.Linq.dll");

        String compileSource =
          "using System.Linq;" + System.Environment.NewLine
        + "namespace " + tempNamespace + " {" + System.Environment.NewLine
        + "    public class " + tempClassName + System.Environment.NewLine
        + "    {" + System.Environment.NewLine
        + "        public System.Collections.Generic.IEnumerable&amp;lt;" + typeof(T).FullName + "&amp;gt; " + tempFuncName + "(System.Collections.Generic.IEnumerable&amp;lt;" + typeof(T).FullName + "&amp;gt; data, System.Predicate&amp;lt;" + typeof(T).FullName + "&amp;gt; predicater)" + System.Environment.NewLine
        + "        {" + System.Environment.NewLine
        + "            return " + linqText + System.Environment.NewLine
        + "        }" + System.Environment.NewLine
        + "    }" + System.Environment.NewLine
        + "}" + System.Environment.NewLine;
        CompilerResults cr = provider.CompileAssemblyFromSource(cp, compileSource);
        if (cr.Errors.HasErrors)
        {
            throw new System.Exception("構文エラーらしいよ。");
        }
        else
        {
            Assembly asm = cr.CompiledAssembly;
            Type tempClassType = asm.GetType(tempNamespace + "." + tempClassName);
            Object classInstance = Activator.CreateInstance(tempClassType);
            MethodInfo methodInfo = tempClassType.GetMethod(tempFuncName);
            Object result = methodInfo.Invoke(classInstance, BindingFlags.InvokeMethod, null, new Object[] { data, predicater }, CultureInfo.CurrentCulture);
            return (System.Collections.Generic.IEnumerable&amp;lt;T&amp;gt;)result;
        }
    }
}
&lt;/pre&gt;&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/132255.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>T.Hirase</dc:creator><title>[C#] 名前付き定数・・・？</title><link>http://blogs.wankuma.com/hirase/archive/2008/03/28/130154.aspx</link><pubDate>Fri, 28 Mar 2008 01:01:00 GMT</pubDate><guid>http://blogs.wankuma.com/hirase/archive/2008/03/28/130154.aspx</guid><wfw:comment>http://blogs.wankuma.com/hirase/comments/130154.aspx</wfw:comment><comments>http://blogs.wankuma.com/hirase/archive/2008/03/28/130154.aspx#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://blogs.wankuma.com/hirase/comments/commentRss/130154.aspx</wfw:commentRss><trackback:ping>http://blogs.wankuma.com/hirase/services/trackbacks/130154.aspx</trackback:ping><description>&lt;p&gt;名前つきの何かを作るためのAttribute。&lt;/p&gt;
&lt;p&gt;たとえば、下の例のように、表示名だけを変えたいようなケースとか、もう少し拡張すれば、多言語化アプリ作成にも役立ちそう。&lt;/p&gt;
&lt;pre class="csharp" xml:space="preserve" name="sourceCode"&gt;using System;
using System.Reflection;

namespace Sample
{
    internal class Program
    {
        enum Windows
        {
            [Name("Windows 95")]
            Chicago,
            [Name("Windows 95 OSR2")]
            Detroit,
            [Name("Windows 98")]
            Memphis,
            [Name("Windows 2000")]
            Cairo,
            [Name("Windows Me")]
            Georgia,
            [Name("Windows XP")]
            Whistler,
            [Name("Windows Vista")]
            Longhorn,
        }

        private static void Main(string[] args)
        {
            foreach (object value in Enum.GetValues(typeof(Windows)))
            {
                String name = NameAttribute.GetName(value as Enum);
                Console.WriteLine(name);
            }
        }
    }

    [AttributeUsage(AttributeTargets.All)]
    public class NameAttribute : Attribute
    {
        public String Name
        {
            get;
            private set;
        }

        public NameAttribute(String name)
        {
            this.Name = name;
        }

        public static String GetName(MemberInfo type)
        {
            Attribute[] attributes;
            attributes = type.GetCustomAttributes(typeof(NameAttribute), true) as Attribute[];
            if (attributes == null || attributes.Length == 0)
                return null;

            NameAttribute nameAttribute = attributes[0] as NameAttribute;
            return nameAttribute.Name;
        }

        public static String GetName(Enum enumValue)
        {
            Type enumType = enumValue.GetType();
            String enumName = Enum.GetName(enumType, enumValue);

            return GetName(enumType.GetField(enumName));
        }
    }
}&lt;/pre&gt;&lt;img src ="http://blogs.wankuma.com/hirase/aggbug/130154.aspx" width = "1" height = "1" /&gt;</description></item></channel></rss>