[B][U]Option 2[/U][/B]
string str = "";
for (int i = 0; i < Data.Length; i++)
{
str += (char)Data[i++]) ;
}
[B][U]Option 2[/U][/B]
string str = "";
for (int i = 0; i < Data.Length; i++)
{
str += (char)Data[B][COLOR="Red"][i][/COLOR][/B] ;
}
Still got the round bracket after the data which shouldn't be there.
Prefer option 2 for readability. Option 1 is neat, but put that into 1000 lines of code, and ask someone to troubleshoot your code and they probably going to want to shoot you.
Okay then would you agree that this is still better than option 1:
Code:string str = ""; for (int i = 0; i < Data.Length; i++) { str += (char)Data[i] ; }
Any comments on this coding style?
Code:[u][b]Option 1[/b][/u] string str = ""; for (int i = 0; i < Data.Length; str += (char)Data[i++]) ;
As apposed to this:
Code:[u][b]Option 2[/b][/u] string str = ""; for (int i = 0; i < Data.Length; i++) { str += (char)Data[i] ; }
My vote is for option 2, option 1 is just nasty.
I've never done development for living, so this might be stupid question. Doesnt your project manager / leader / corrdinator etc decide on a style beforehand? If read through code I like seeing the style being applied right through, nevermind how small a particular statement might be. So option 2 for me then.
Any comments on this coding style?
Code:[u][b]Option 1[/b][/u] string str = ""; for (int i = 0; i < Data.Length; str += (char)Data[i++]) ;
As apposed to this:
Code:[u][b]Option 2[/b][/u] string str = ""; for (int i = 0; i < Data.Length; i++) { str += (char)Data[i] ; }
My vote is for option 2, option 1 is just nasty.
Actually I think the best method (in this example) is to use StringBuilder.
I'm willing to bet that has something to do with the fact that strings are immutable in Java (and c#);
Prefer option 2 for readability. Option 1 is neat, but put that into 1000 lines of code, and ask someone to troubleshoot your code and they probably going to want to shoot you.
string str = string.Empty;
for (int i = 0; i < Data.Length; i++){
str += (char)Data[i];
}