C# 为什么我的CheckedListBox的ItemText被视为;0";?

C# 为什么我的CheckedListBox的ItemText被视为;0";?,c#,winforms,checkedlistbox,C#,Winforms,Checkedlistbox,使用此代码: for (int i = 0; i <= (checkedListBoxPlatypi.Items.Count - 1); i++) { if (checkedListBoxPlatypi.GetItemCheckState(i) == CheckState.Checked) { ReturnListPlatypi.Add(ParsePlatypusID(checkedListBoxPlatypi.GetItemText(i))); }

使用此代码:

for (int i = 0; i <= (checkedListBoxPlatypi.Items.Count - 1); i++)
{
    if (checkedListBoxPlatypi.GetItemCheckState(i) == CheckState.Checked)
    {
        ReturnListPlatypi.Add(ParsePlatypusID(checkedListBoxPlatypi.GetItemText(i)));
    }
}

…ParsePlatypusID()被传递为“0”…?

我假设您没有将“I”添加到列表框,因此该对象不会有任何文本。您只需直接使用对象:

for (int i = 0; i <= (checkedListBoxPlatypi.Items.Count - 1); i++)
{
    if (checkedListBoxPlatypi.GetItemCheckState(i) == CheckState.Checked)
    {
        ReturnListPlatypi.Add(ParsePlatypusID(checkedListBoxPlatypi.Items[i].ToString()));
    }
}

for(int i=0;i@J:No,“Friendly Platypus”是一个类似于“Platypi R Us(314)/(42)”的字符串,而不是一个枚举(为了尽职调查,我试着在它后面加上.ToString(),但没有什么区别)。@Clay Shannon编辑,因为我显然完全错过了这条船。
for (int i = 0; i <= (checkedListBoxPlatypi.Items.Count - 1); i++)
{
    if (checkedListBoxPlatypi.GetItemCheckState(i) == CheckState.Checked)
    {
        ReturnListPlatypi.Add(ParsePlatypusID(checkedListBoxPlatypi.Items[i].ToString()));
    }
}
for (int i = 0; i <= (checkedListBoxPlatypi.Items.Count - 1); i++)
{
    if (checkedListBoxPlatypi.GetItemCheckState(i) == CheckState.Checked)
    {
        ReturnListPlatypi.Add(ParsePlatypusID(checkedListBoxPlatypi.GetItemText( checkedListBoxPlatypi.Items[i])));
    }
}