publicclassKata{publicstaticstringStringify(Node list)=> list ==null?"null": list.Data +" -> "+Stringify(list.Next);}
答案2:
using System;using System.Collections.Generic;publicclassKata{privatestatic IEnumerable<string>Adapt(Node list){for(; list !=null; list = list.Next)yieldreturn list.Data.ToString();yieldreturn"null";}publicstaticstringStringify(Node list)=> String.Join(" -> ",Adapt(list));}
using System;publicclassKata{publicstaticstringStringify(Node list){if(list ==null){return"null";}string result = String.Empty;Node tempnode = list;if(tempnode.Next ==null){
result += tempnode.Data +" -> null";return result;}do{
result += tempnode.Data +" -> ";if(tempnode.Next.Next ==null){
result += tempnode.Next.Data +" -> null";}
tempnode = tempnode.Next;}while(tempnode.Next !=null);return result;}}
答案6:
using System.Text;publicstaticclassKata{publicstaticstringStringify(Node list){var builder =newStringBuilder();for(; list !=null; list = list.Next){
builder.Append(list.Data).Append(" -> ");}return builder.Append("null").ToString();}}
答案7:
using System;publicclassKata{publicstaticstringStringify(Node list){string resulat ="";while(list !=null){
resulat = String.Concat(resulat, list.Data.ToString()," -> ");
list = list.Next;}
resulat = String.Concat(resulat,"null");return resulat;}}