Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Simple loop in C#
Message
From
09/10/2006 13:10:31
Keith Payne
Technical Marketing Solutions
Florida, United States
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01160532
Message ID:
01160626
Views:
15
>>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
return new string(s.ToCharArray().Reverse());
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform