Re[13]: C# [Proposal] init block for safe initialization of
От: Serginio1 СССР https://habrahabr.ru/users/serginio1/topics/
Дата: 25.12.25 15:40
Оценка:
Здравствуйте, Sinclair, Вы писали:


S>попытка 2:

S>
S>var node1 = new Node("Hello") { Next = null!, Previous = null! }; 
S>var node2 = new Node("World") { Next = node1, Previous = node1) }; 
S>node1.Previous = node2;
S>foreach(var n in Iterate(node1)
S>  Console.WriteLine(n);
S>

S>Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.

S>Попробуйте решить проблему при помощи EmptyNode.



var node1 = new Node("Hello") { Next = Node.EmptyNode, Previous = Node.EmptyNode }; 
var node2 = new Node("World") { Next = node1, Previous = Node.EmptyNode) }; 
node1.Previous = node2;
foreach(var n in Iterate(node1)
Console.WriteLine(n);


И никаких System.NullReferenceException
и солнце б утром не вставало, когда бы не было меня
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.