2010-03-06 6 views
0

내 코드를 수정하는 데 정말로 어려움을 겪고있는 Im은 저를 도와 줄 수있는 사람이 있는지 궁금합니다.C# : 누구든지이 문제를 해결하는 방법을 알고 있습니까? : 형식 또는 네임 스페이스 이름 'T'을 (를) 찾을 수 없습니다.

기본적으로 다음과 같은 오류 점점 메신저 : (당신은 using 지시문 또는 어셈블리 참조가?)

다음

내 클래스입니다 형식 또는 네임 스페이스 이름 'T는'을 (를) 찾을 수 없습니다

를 :

프로그램 등급 :

using System; 
using System.Collections.Generic; 
using System.Text; 

namespace LinkedListGen 

{ 
    class program 
    { 
     public static void Main(string[] args) 
     { 
      LinkListGen<T> testList = new LinkListGen<T>(); 
      Console.ReadKey(); 
     } 
    } 
} 

LinkGen 등급 :

using System; 
using System.Collections.Generic; 
using System.Text; 

namespace LinkedListGen 
{ 
class LinkGen<T> 
{ 
    private T data; 
    private LinkGen<T> next; 

    public LinkGen(T item) 
    { 
     data = item; 
     next = null; 
    } 

    public LinkGen(T item, LinkGen<T> list) 
    { 
     data = item; 
     next = list; 
    } 

    public LinkGen<T> TailList 
    { 
     set { this.next = value; } 
     get { return this.next; } 
    } 

    public T HeadList 
    { 
      set { this.data = value; } 
      get { return this.data; } 
     } 

    } 
} 

LinkListGen 클래스 :

using System; 
using System.Collections.Generic; 
using System.Text; 

namespace LinkedListGen 
{ 
public class LinkListGen<T> where T : IComparable 
{ 
    private LinkGen<T> list; 

    public LinkListGen() //initialise list to be empty 
    { 
     list = null; 
    } 

    public void AddItem(T item) 
    { 
     list = new LinkGen<T>(item, list); 
    } 
    public string DisplayList() //write items to string 
    { 
     LinkGen<T> temp = list; 
     string buffer = ""; 
     while (temp != null) 
     { 
      Console.WriteLine(temp.HeadList); 
      temp = temp.TailList; 
     } 
     return buffer; 
    } 
    public int NumberOfItems() 
    { 
     LinkGen<T> temp = list; 
     int count; 
     count = 0; 
     while (temp != null) 
     { 
      count++; 
      temp = temp.TailList; 
     } 
     Console.Out.WriteLine("There are " + count + "items recorded."); 
     return count; 
    } 

    public bool IsPresentItem(T item) 
    { 
     bool txf; 
     LinkGen<T> temp = list; 
     int count; 
     count = 0; 
     while (temp != null) 
     { 
      if (item.Equals(temp.HeadList)) 
      { 
       count++; 
      } 
      temp = temp.TailList; 
     } 
     if (count > 0) 
     { 
      Console.Out.WriteLine("There are " + count + " instances of " + item + "."); 
      txf = true; 
     } 
     else 
     { 
      Console.Out.WriteLine("There are no instances of " + item + "."); 
      txf = false; 
     } 
     return txf; 

    } 

    public void RemoveItem(T item) 
    { 
     LinkGen<T> prev = list; 
     LinkGen<T> curr = list; 
     if (item.Equals(curr.HeadList)) 
      list = curr.TailList; 
     else 
     { 
      while (curr != null) 
      { 
       if (item.Equals(curr.HeadList)) 
       { 
        prev.TailList = curr.TailList; 
       } 
       else 
       { 
        prev = curr; 
        curr = curr.TailList; 
       } 
      } 
     } 
    } 
} 
} 

목표는 일반적인 연결리스트

임 정말 내 지혜의 끝을 만드는 것입니다 및 제공 어떤 도움을 주셔서 감사합니다. 예를 들어

public static void Main(string[] args) 
    { 
     LinkListGen<T> testList = new LinkListGen<T>(); 
        ^       ^
     Console.ReadKey(); 
    } 

:

 LinkListGen<string> testList = new LinkListGen<string>(); 
+0

코드 줄에 오류가 있습니까? –

답변

10

당신은 T, 오히려 형의 자리보다, 여기에 구체적인 유형을 지정해야 일반 목록에 사용하려는 유형으로

+0

아아 맞아. 그냥 자리 표시 자일 뿐이야. 나는 처음에 그것을 유형으로 대체하려고 시도했을 때 내가 잘못하고 있다고 생각했다. 어리석은 나를. 고맙습니다. – user287572

6
LinkListGen<T> testList = new LinkListGen<T>(); 

당신은 여기 '를 T'를 교체해야

관련 문제