2012-11-10 18 views
1

我正在從Windows窗體應用程序導航到Windows應用商店。我從網上獲得的課程如下所示,什麼是Windows 8商店應用程序中的c#CollectionBase的替換?

public class ElementList : CollectionBase 
{ 
    /// <summary> 
    /// A Collection of Element Nodes 
    /// </summary>  
    public ElementList() 
    {   
    } 

    public void Add(Node e) 
    { 
     // can't add a empty node, so return immediately 
     // Some people tried dthis which caused an error 
     if (e == null) 
      return; 

     this.List.Add(e); 
    } 

    // Method implementation from the CollectionBase class 
    public void Remove(int index) 
    { 
     if (index > Count - 1 || index < 0) 
     { 
      // Handle the error that occurs if the valid page index is  
      // not supplied.  
      // This exception will be written to the calling function    
      throw new Exception("Index out of bounds");    
     }   
     List.RemoveAt(index);   
    } 

    public void Remove(Element e) 
    {   
     List.Remove(e);   
    } 

    public Element Item(int index) 
    { 
     return (Element) this.List[index]; 
    } 


} 

在上面的類中,商店應用程序不接受CollectionBase。請告訴我一種將其導航到Windows 8商店應用程序的方法。 。 。

在此先感謝!

回答

2

你不需要使用

IList 

,而不是你可以使用

List<Object>. . . 

只要給它一試。 。 。

它爲我工作可能也適用於你..

1

我覺得其實我想通了,CollectionBase的自IList繼承,所以我重寫代碼如下,

public class ElementList 
{ 
    public IList List { get; } 
    public int Count { get; } 


    public ElementList() 
    { 

    } 

    public void Add(Node e) 
    { 
     if (e == null) 
     { 
      return; 
     } 

     this.List.Add(e); 
    } 

    public void Remove(int index) 
    { 
     if (index > Count - 1 || index < 0) 
     { 
      throw new Exception("Index out of bounds"); 
     } 
     List.RemoveAt(index);   
    } 

    public void Remove(Element e) 
    { 
     List.Remove(e); 
    } 

    public Element Item(int index) 
    { 
     return (Element)this.List[index]; 
    } 

} 

如果有任何修改,或者如果我做錯了什麼手段,請說!

在此先感謝!

0

作爲一種替代方案,您可以隨時編寫自己的CollectionBase來做同樣的事情。

相關問題