简体   繁体   中英

c# storing reversed string into another string

block1 works:-

String input = "The quick brown fox jumps over the lazy dog";
char[] output = input.Reverse().ToArray();
Console.WriteLine(output);

when I try to store the output into a new String , block2 works as well:-

String input = "The quick brown fox jumps over the lazy dog";
char[] output = input.Reverse().ToArray()
String output2 = new String(output);
Console.WriteLine(output2);

But when I try to store the output into a String , block3 does not works:-

String input = "The quick brown fox jumps over the lazy dog";
char[] output = input.Reverse().ToArray()
String output2 = output; //I tried to use convert.ToString() as well,  but it didn't work
Console.WriteLine(output2);

why does block 2 works and block 3 does not??

You forgot to convert the char[] into a string

String input = "The quick brown fox jumps over the lazy dog";
char[] output = input.Reverse().ToArray();
String output2 = new string(output); 
Console.WriteLine(output2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM