does any of you know what would be better:
a. get a string s, convert to char array and loop over it, or
b. get a string s, loop over substrings of it (s.Substring(i, 1))?
Any tips much appreciated.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Option b), looping over substrings, is very inefficient.
The fastest method would be
c) loop over the string chars directly, using the read-only indexer property:
or, based on the
IEnumerable<char>interface: