我正在尝试为项目打印ASCII艺术作品。看起来像这样:
var array = new string[]
{
@" ``````` `..`.`` ``.``.` ",
@" +ooooo- -ooooo+ :ooooo/ ",
@" +ooooo- -ooooo+ :oooso: ",
@" +ooooo- .+oo++/ :++oo+: ",
@" +ooooo- `......```..```.```......` ",
@" +ooooo- `.`......`..``..``.....`.` ",
@" +ooooo- `.........`....`.........` ",
@" +ooooo- /mmmmmmmmmmmmmmmmmm+.....` ",
@" +ooooo- /MMMMMMMMMMMMMMMMMM+`....` ",
@" +ooooo- /MMMMMMMMMMMMMMMMMM+.....` ",
@" +ooooo- .+++++oMMMMMMo++//+-`....` ",
@" +ooooo- ``...`-MMMMMM-....`......` ",
@" +ooooo- ``...`-MMMMMM-...........` ",
@" ::::::.``````......ssssss/::::::::::::----:- ",
@" `....................`...+ooooooooooooooooo+ ",
@" `...............`........ooooooo+oooooooooo+ ",
@" `````````````............+ooooo+/////+ooooo+ ",
@" `.....`.....`+oooo+:.`...:ooooo+ ",
@" `............+ooooo:````.:ooooo+ ",
@" ``....`..`...+ooooo:.....:ooooo+ ",
@" `....``...`..+ooooooooooooooooo+ ",
@" `............oooooooooooooooooo+ ",
@" `......````..++++++oooooo++oo++/ ",
@" `...``` ```````.....`````` ",
@" `.....` `....`` ",
@" `.....` `.``.`` "
};
foreach (string line in arr)
Console.WriteLine(line);
到目前为止,它已经可以使用了,但是我希望能够像这样水平打印:
镜像:
我想不出办法。我已经尝试过Array.Reverse,但是它将图像颠倒打印。
答案 0 :(得分:0)
Array.Reverse
不会使阵列反转,而是返回阵列的反转版本。因此,只需将其设置为新变量并打印:
foreach (string line in arr.Reverse())
Console.WriteLine(line);
答案 1 :(得分:0)
使您自己成为扩展方法来反转字符串,这样您就可以遍历数组并分别反转每一行
public static class Extensions
{
public static string Reverse(this string s)
{
var charArray = s.ToCharArray();
Array.Reverse(charArray);
return new string (charArray);
}
}
用法
foreach (string line in array)
Console.WriteLine(line.Reverse());
输出
`.``.`` ``.`..` ```````
/ooooo: +ooooo- -ooooo+
:osooo: +ooooo- -ooooo+
:+oo++: /++oo+. -ooooo+
`......```.```..```......` -ooooo+
`.`.....``..``..`......`.` -ooooo+
`.........`....`.........` -ooooo+
`.....+mmmmmmmmmmmmmmmmmm/ -ooooo+
`....`+MMMMMMMMMMMMMMMMMM/ -ooooo+
`.....+MMMMMMMMMMMMMMMMMM/ -ooooo+
`....`-+//++oMMMMMMo+++++. -ooooo+
`......`....-MMMMMM-`...`` -ooooo+
`...........-MMMMMM-`...`` -ooooo+
-:----::::::::::::/ssssss......``````.::::::
+ooooooooooooooooo+...`....................`
+oooooooooo+ooooooo........`...............`
+ooooo+/////+ooooo+............`````````````
+ooooo:...`.:+oooo+`.....`.....`
+ooooo:.````:ooooo+............`
+ooooo:.....:ooooo+...`..`....``
+ooooooooooooooooo+..`...``....`
+oooooooooooooooooo............`
/++oo++oooooo++++++..````......`
``````.....``````` ```...`
``....` `.....`
``.``.` `.....`