WP7 - 价值不在预期范围内

时间:2015-05-09 07:20:38

标签: c# windows-phone-7 dictionary

我正在尝试将项目添加到词典中。我用以下代码将值添加到Dictionary中。

Console.WriteLine("selectedCategories.Count==> " + selectedCategories.Count);
selectedCategoryMap = new Dictionary<String, Category>();
     if (selectedCategories != null)
       {
          foreach (Category category in selectedCategories)
            {
               selectedCategoryMap.Add(category.getCategoryID(), category);
            }
       }

我最多可以插入58个项目。当我尝试添加第59项时,我得到了以下错误。

System.ArgumentException was unhandled
  Message=Value does not fall within the expected range.
  StackTrace:
       at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
       at System.Collections.Generic.Dictionary`2.Insert(String key, Category value, Boolean add)
       at System.Collections.Generic.Dictionary`2.Add(String key, Category value)
       at TestReactive.com.beno.WP7Client.ViewModels.ListCategoriesViewModel.finalSelected(ListCategoriesModel items)
       at GalaSoft.MvvmLight.Command.RelayCommand`1.Execute(Object parameter)
       at System.Windows.Controls.Primitives.ButtonBase.ExecuteCommand()
       at System.Windows.Controls.Primitives.ButtonBase.OnClick()
       at System.Windows.Controls.Button.OnClick()
       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

我的分类

 public class Category
    {

        private String categoryID;
        private String categoryName;

        public String getCategoryID()
        {
            return categoryID;
        }

        public void setCategoryID(String categoryID)
        {
            this.categoryID = categoryID;
        }

        public String getCategoryName()
        {
            return categoryName;
        }

        public void setCategoryName(String categoryName)
        {
            this.categoryName = categoryName;
        }
}

请告诉我错误的地方。

0 个答案:

没有答案