C
C#2y ago
Ryan-T1412

❔ ✅ using multiple methods to object

.
17 Replies
Ryan-T1412
Ryan-T1412OP2y ago
ok so before reversing the string we should convert it to an array, right? why it's not number.ToArray().Reverse()
Thinker
Thinker2y ago
string already implements IEnumerable<char> so there's no need to
MODiX
MODiX2y ago
thinker227#5176
REPL Result: Success
"foo bar".Reverse()
"foo bar".Reverse()
Result: ReverseIterator<char>
[
"r",
"a",
"b",
" ",
"o",
"o",
"f"
]
[
"r",
"a",
"b",
" ",
"o",
"o",
"f"
]
Compile: 436.640ms | Execution: 25.682ms | React with ❌ to remove this embed.
Thinker
Thinker2y ago
Also new string(numb.ToString()) isn't necessary, you can just do numb.ToString()
Ryan-T1412
Ryan-T1412OP2y ago
how about next line ?
string reversedNumber = new string(number.Reverse().ToArray());
string reversedNumber = new string(number.Reverse().ToArray());
if i remove new string it gaves an error
Thinker
Thinker2y ago
You need it there because ToArray() returns a char[], and new string creates a string from a char[] .
Ryan-T1412
Ryan-T1412OP2y ago
i see
string reversedNumber = number.Reverse();
string reversedNumber = number.Reverse();
but what if i do it like this insted of converting string -> array -> string
Thinker
Thinker2y ago
That won't work because you can't convert an IEnumerable<char> to a string.
MODiX
MODiX2y ago
thinker227#5176
REPL Result: Failure
string reversed = "123".Reverse();
string reversed = "123".Reverse();
Exception: CompilationErrorException
- Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<char>' to 'string'. An explicit conversion exists (are you missing a cast?)
- Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<char>' to 'string'. An explicit conversion exists (are you missing a cast?)
Compile: 437.548ms | Execution: 0.000ms | React with ❌ to remove this embed.
ero
ero2y ago
Now i wonder what the fastest way to reverse is...
Thinker
Thinker2y ago
string.Create probably
ero
ero2y ago
Because it always is But there's more nuance to it Because you don't necessarily have to turn the number into a string first
Thinker
Thinker2y ago
however, that was not the question, so let's not get sidetracked catsip
ero
ero2y ago
I wanna side track!
Thinker
Thinker2y ago
go to #allow-unsafe-blocks when
Ryan-T1412
Ryan-T1412OP2y ago
thank you !close
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server