I duno why i will get infinite loop like tis in c#. Pls Help! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I duno why i will get infinite loop like tis in c#. Pls Help!

does anyone know why my tis code get infinite loop? and Char.IsUpper is not exactly run wat i think or i use it wrong? https://code.sololearn.com/cVnmR1XN10F3 when take out the for loop it has no problem. https://code.sololearn.com/c3eNqkaDBYqu

17th Mar 2020, 2:59 AM
Jeffrey Lee
Jeffrey Lee - avatar
3 Answers
+ 4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { string x = "someCase"; int y =x.Length ; for(int i=0; i<y; i++) { if(Char.IsUpper(x,i)); { x = x.Insert(i,"_"); } Console.WriteLine(x); } } } }
17th Mar 2020, 3:05 AM
Cmurio
Cmurio - avatar
+ 4
Every time you inserted a '_' it modified the character size of the string
17th Mar 2020, 3:07 AM
Cmurio
Cmurio - avatar
0
thx. i think i know wat u mean. but i stil dun get it why i insert '_' is not at previous capital letter? but it shows at 1st index? EDIT: i found the mistake d. thx for the help
17th Mar 2020, 3:26 AM
Jeffrey Lee
Jeffrey Lee - avatar