Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Simple loop in C#
Message
From
09/10/2006 13:03:57
 
 
To
09/10/2006 10:07:05
Keith Payne
Technical Marketing Solutions
Florida, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01160532
Message ID:
01160621
Views:
14
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform