1

Windows フォーム アプリから Windows ストア アプリにクラスを移動しています。インターネットから取得したクラスを以下に示します。

    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 ストア アプリに移動する方法を教えてください。. .

前もって感謝します!

4

4 に答える 4

2

使用する必要はありません

    IList 

代わりに使用できます

    List<Object>. . .

試してみてください。。。

それは私のために働いたそれはあなたのためにも働くかもしれません。

于 2012-12-24T11:57:36.410 に答える
1

WinRTではSystem.Collections.ObjectModelまたはSystem.Collections.Genericを使用する必要があります

CollectionBaseは廃止されたため、使用を避ける必要があります。

于 2012-11-10T06:41:57.813 に答える
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];
    }

}
于 2012-11-10T11:38:00.760 に答える
0

CollectionBase別の方法として、同じことを行う独自の方法をいつでも作成できます。

于 2012-11-10T12:18:59.133 に答える