以下の内容はhttps://baba-s.hatenablog.com/entry/2019/09/03/231000より取得しました。


【C#】Dictionary を foreach で使う時の記述を簡略化する Deconstruction

ソースコード

using System.Collections.Generic;

public static class KeyValuePairExt
{
    public static void Deconstruct<TKey, TValue>
    (
        this KeyValuePair<TKey, TValue> self,
        out  TKey                       key,
        out  TValue                     value
    )
    {
        key   = self.Key;
        value = self.Value;
    }
}

使用例

通常

foreach ( var elem in m_table )
{
    Debug.Log( elem.Key + ": " + elem.Value );
}

Deconstruction

foreach ( var ( key, value ) in m_table )
{
    Debug.Log( key + ": " + value );
}



以上の内容はhttps://baba-s.hatenablog.com/entry/2019/09/03/231000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14