variable=字典中的类在使用后重置/清除var
本文关键字:var 清除 字典 variable | 更新日期: 2023-09-27 18:28:43
我对Var"item"有问题,我从xml循环中调用Method MyItems,并按键从Dictionary中选择类,出于某种原因,数量是正确的,但它们都来自相同的类型/值/图标。。。。。
添加到_list.Add(item)后,我如何重置、清除、null或其他任何"项"。。。。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;
}
}
}
感谢
添加后,我如何重置、清除、null或其他"项"到_list.Add(item)…新建到c#。。。。。。
如果我正确理解您的问题,那么在将项目添加到_list后,您希望将其从_objectsToList中删除。这可以通过以下方式完成:
_objectToList.Remove(funcid);
有关使用此方法或Dictionary集合的详细信息,请参阅:http://msdn.microsoft.com/en-us/library/xfhwa508.aspx