C#
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,648 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
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(first);
//list.AddLast(second);
//list.AddLast(third);
//list.AddLast(fourth);
//list.AddLast(fifth);
//list.AddLast(sixth);
//// list.AddLast(seventh);
}
}
You need to specify the type e.g. LinkedList<Node<string>> list = new();