2012-11-10 2 views
1

Windows에서 수업 탐색하기 Forms 앱을 Windows 앱에 저장합니다. 내가 인터넷에서있어이 클래스는 CollectionBase에이 스토어 앱으로 인정되지 않는다 위의 클래스에서 아래Windows 8 Store 앱에서 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]; 
    } 


} 

을 표시됩니다. Windows 8 앱으로 이동하는 방법을 알려주세요. . .

미리 감사드립니다.

답변

2

당신은 그것을 시도를 제공

IList 

를 사용할 필요가 없습니다. . .

그것은 나를 위해 일한 것 같습니다.

1

당신은

CollectionBase이 사용되지 않습니다 WinRT에 System.Collections.ObjectModel 또는 System.Collections.Generic을 사용해야하고 당신이 그것을 사용하지 않아야합니다.

+0

답장을 보내 주셔서 감사합니다. 위 코드에서 List.Add()를 사용하여 System.Collections.ObjectModel 또는 System.Collections.Generic을 사용하여 어떻게 할 수 있습니까? . . – ggsmartboy

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을 작성할 수 있습니다. 대신 당신이

List<Object>. . . 

을 사용할 수 있습니다

관련 문제