Generic Linked List in C#

Shervan360 1,481 Reputation points


How can I solve the error in Line 12?

using System.Collections.Generic;

class Node<T>  
    public T Value { get; set; }  
    public Node<T> Next { get; set; }  
    public Node(T val) => Value = val;  
class Program  
    public static void Main()  
        LinkedList<Node> list = new(); //error  
        Node<int> first = new(10);  
        Node<string> second = new("Daniel");  
        Node<int> third = new(17);  
        Node<char> fourth = new('a');  
        Node<int> fifth = new(1);  
        Node<int> sixth = new(50);  
        // Node seventh = new(100);  
        //// list.AddLast(seventh);  
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,390 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,201 Reputation points

    You need to specify the type e.g. LinkedList<Node<string>> list = new();

    1 person found this answer helpful.
    0 comments No comments