Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Simple loop in C#
Message
From
10/10/2006 04:19:26
 
 
To
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:
01160766
Views:
20
>>>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());
>
1 out of 10. Test before submitting <g>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform