Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Simple loop in C#
Message
De
10/10/2006 04:20:46
 
 
À
09/10/2006 13:10:47
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01160532
Message ID:
01160767
Vues:
24
>>>C#:
>>>
>>>
>>>			string source = "Hello World";
>>>			string result = String.Empty;
>>>			char[] srcArray = source.ToCharArray();
>>>
>>>			int i;
>>>
>>>			if (srcArray.Length > 0)
>>>			{
>>>				for (i=srcArray.Length-1;i>-1;i--)
>>>				{
>>>					result += srcArray[i];
>>>				}
>>>			}
>>>
>>>
>>>Straight C is a little more code.
>>
>>Shorter C# (maybe not faster):
>>public String Reverse (string s)
>>{
>>    char[] c = s.ToCharArray();
>>    Array.Reverse(c);
>>    return new String(c);
>>}
>>
Best,
>>Viv
>
>Shouldn't it be faster and more efficient? Other version is creating multiple strings.

Maybe, haven't tested. But Array.Reverse() has to do something...
Regards,
Viv
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform