publicstaticstringDiamond(ulongn){if((n%2)==0)returnnull;ulongmaxIndent=(n-1)/2;StringBuildersb=newStringBuilder();sb.WriteRows(maxIndent,maxIndent,end=>end>0,i=>i-1);sb.WriteRows(maxIndent,0,end=>end<=maxIndent,i=>i+1);returnsb.ToString();}publicstaticvoidWriteRows(thisStringBuildersb,ulongmaxIndent,ulongstart,Func<ulong,bool>condition,Func<ulong,ulong>step){for(ulongindent=start;condition(indent);indent=step(indent)){sb.WriteChars(indent,' ');sb.WriteChars(maxIndent-indent,'*');sb.Append("*");sb.WriteChars(maxIndent-indent,'*');sb.WriteChars(indent,' ');sb.WriteLine();//make a NewLine}}privatestaticvoidWriteChars(thisStringBuildersb,ulongcount,charc){for(ulongi=0;i<count;++i){sb.Append(c);}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A bit late, but with functional flavoured C#