c#泛型出错了

[复制链接]
查看11 | 回复2 | 2010-8-7 10:38:17 | 显示全部楼层 |阅读模式
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace 创建泛型2
{

public class LinkedListNode1

{

private T value;

public LinkedListNode1(T value)

{

this.value = value;

}

public T Value

{

get { return value; }

}

private LinkedListNode1 next;

public LinkedListNode1 Next

{

get { return next; }

internal set { next = value; }

}

private LinkedListNode1 prev;

public LinkedListNode1 Prev

{

get { return prev; }

internal set { next = value; }

}

}

public class LinkedList1 : IEnumerable

{

private LinkedListNode1 first;

public LinkedListNode1 First

{

get { return first; }

}

private LinkedListNode1 last;

public LinkedListNode1 Last

{

get { return last; }

}

public LinkedListNode1 AddLast(T node)

{

LinkedListNode1 newnode = new LinkedListNode1(node);

if (first == null)

{

first = newnode;

last = first;

}

else

{

last.Next = newnode;

last = last.Next;

}

return newnode;

}

public IEnumerator GetEnumerator()

{

LinkedListNode1 current = first;

while (current != null)

{

yield return current.Value;

current = current.Next;

}

}

IEnumerator IEnumerable.GetEnumerator()

{

return GetEnumerator();

}

public static void Main(string[] args)

{

LinkedList1 list2 = new LinkedList1();

list2.AddLast(1);

list2.AddLast(2);

list2.AddLast(5);

foreach (int i in list2)

{

Console.WriteLine(i);

}

}

}
}
错误说明:
1。错误 1 程序“E:\application\ConsoleApplication6\ConsoleApplication6\obj\Debug\ConsoleApplication6.exe”不包含适合于入口点的静态“Main”方法 ConsoleApplication6
2。错误 警告 2 “创建泛型2.LinkedList1.Main(string[])”: 入口点不能是泛型的或属于泛型类型 E:\application\ConsoleApplication6\ConsoleApplication6\Program.cs 78 28 ConsoleApplication6

回复

使用道具 举报

千问 | 2010-8-7 10:38:17 | 显示全部楼层
你不能把Main方法放到类LinkedList1里面我将代码稍微改了下,在我这里VS2008里测试通过了using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Collections;namespace 创建泛型2{
public class LinkedListNode1
{
private T value;
public LinkedListNode1(T value)
{

回复

使用道具 举报

千问 | 2010-8-7 10:38:17 | 显示全部楼层
错误信息显示得很明白了。你的Main函数是不能写在一个泛型类型里面的。你可以另外建个类型class Program{ //....把Main放这里面}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行