Skip to main content
 首页 » 编程设计

c#之Windows 8 Store Apps 中 c# CollectionBase 的替代品是什么

2024年02月20日22softidea

我正在将一个类从 Windows 窗体应用程序导航到 Windows 应用商店应用程序。我从网上得到的类(class)如下所示,

    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 商店应用程序的方法。 . .

提前致谢!

请您参考如下方法:

你不需要使用

    IList  

相反你可以使用

    List<Object>. . . 

试试吧。 . .

它对我有用可能对你也有用..