变量=使用后字典重置/清除var的类

时间:2012-03-22 11:07:26

标签: c# .net-cf-3.5

我在这里遇到Var“item”的问题,我从xml循环中调用Method MyItems,并按字典从Dictionary中选择类,由于某种原因,数量是正确的,但它们都来自相同的类型/值/图标.....

如何将它添加到_list.Add(item)之后重置,清除,null或任何“item”.... 新的c#......

*我希望我的邮政编码/格式现在正确无误:p

public class ISwitch : Form1
{
    private static Dictionary<int, Base> _objectsToList;
    private static bool _dicSet = false;

    // Build Dictionary 
    static ISwitch()
    {
        Debug.Write("-----------------------------------------------------\n");
        Debug.Write("dic created\n");

        _objectsToList = new Dictionary<int, SenseItemBase>
                             {
                                 {1, new Control()},
                                 {2, new Control2()},
                                 {3, new MoreItems()},
                                 {4, new MoreItems2()}
                             };
        _dicSet = true;
    }

    public static void MyItems(int id, int funcid, string _index, string _text, string icongfx, string property, string type, string _function, string _itemtype)
    {
        if (!_dicSet) return;
        Debug.Write("-----------------------------------------------------\n");
        Debug.Write("ID : " + id + "\n");
        Debug.Write("funcid : " + funcid + "\n");
        Debug.Write("Case : " + _index + "\n");
        Debug.Write("Property : " + property + "\n");
        Debug.Write("Type : " + type + "\n");
        Debug.Write("Function : " + _function + "\n");
        Debug.Write("Icon : " + icongfx + "\n");
        Debug.Write("Text : " + _text + "\n");
        Debug.Write("Switch : " + _itemtype + "\n");
        XFItemStyle Style;

        switch (id)
        {
            case 1:

                if (_objectsToList.ContainsKey(funcid))
                {
                    var item = _objectsToList[funcid];

                    Debug.Write("-----------------------------------------------------\n");
                    Debug.Write("- Item-\n");
                    Debug.Write("_objectsToList : " + item + "\n");
                    Debug.Write("ID : " + id + "\n");
                    Debug.Write("funcid : " + funcid + "\n");
                    item.Style = IStyle.MyStyle(_index, "HelveticaNeue", "HelveticaNeue", out Style);
                    item.MainText = _text;
                    item.myIcon = Path + "\\" + icongfx;

                    _list.Add(item);

                }

                return;

            case 2:
                if (_objectsToList.ContainsKey(funcid))
                {

                    var item = _objectsToList[funcid];

                    Debug.Write("-----------------------------------------------------\n");
                    Debug.Write("- Item action-\n");
                    Debug.Write("_objectsToList : " + item + "\n");
                    Debug.Write("ID : " + id + "\n");
                    item.Style = IStyle.MyStyle(_index, "HelveticaNeue", "HelveticaNeue", out Style);
                    item.MainText = _text;
                    item.SecondaryText = _text;
                    item.myIcon = Path + "\\" + icongfx;

                    _list.Add(item);
                    item = null;
                }

                return;
        }
    }
}

谢谢

1 个答案:

答案 0 :(得分:0)

  

如何在添加后重置,清除,null或任何“项目”   to _list.Add(item).... c#......

的新用户

如果我正确理解了您的问题,您希望在将项目添加到_list后从_objectsToList中删除该项目。这可以通过以下方式完成:

_objectToList.Remove(funcid);  

有关使用此方法或一般字典集合的详细信息,请参阅:http://msdn.microsoft.com/en-us/library/xfhwa508.aspx