내 코드를 수정하는 데 정말로 어려움을 겪고있는 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>();
코드 줄에 오류가 있습니까? –