17 Replies
ok so before reversing the string
we should convert it to an array, right?
why it's not
number.ToArray().Reverse()
string
already implements IEnumerable<char>
so there's no need tothinker227#5176
REPL Result: Success
Result: ReverseIterator<char>
Compile: 436.640ms | Execution: 25.682ms | React with ❌ to remove this embed.
Also
new string(numb.ToString())
isn't necessary, you can just do numb.ToString()
how about next line ?
if i remove new string it gaves an error
You need it there because
ToArray()
returns a char[]
, and new string
creates a string from a char[]
.i see
but what if i do it like this
insted of converting string -> array -> string
That won't work because you can't convert an
IEnumerable<char>
to a string
.thinker227#5176
REPL Result: Failure
Exception: CompilationErrorException
Compile: 437.548ms | Execution: 0.000ms | React with ❌ to remove this embed.
Now i wonder what the fastest way to reverse is...
string.Create
probablyBecause it always is
But there's more nuance to it
Because you don't necessarily have to turn the number into a string first
however, that was not the question, so let's not get sidetracked
I wanna side track!
go to #allow-unsafe-blocks
thank you
!close
Closed!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.