csharp loop backwards

Code Example - csharp loop backwards

                
                        string[] arr = new string[5];
for (int a = arr.Length; --a >= 0;)
{
  // ...
}
                    
                
 

csharp reverse a string for loop

                        
                                ---------------------------------------------------Option 1
foreach (int v in values.Select(x => x).Reverse())
{
      Console.Write(v + " ");
}
---------------------------------------------------Option 2
       public static void Main(string[] args)
        {
            Console.Write( Reverse("ABcdefgH") );
        }

		public static string Reverse(string s)
        {
            string result = String.Empty;
            char[] cArr = s.ToCharArray();
            int end = cArr.Length - 1;

            for (int i = end; i >= 0; i--)
            {
                result += cArr[i];
            }
            return result;
        }
                            
                        
 

csharp for loop backwards

                        
                                int[] myarray = new int[]{1,2,3,4};
for(int i = myarray.Length - 1; i >= 0; i--)
{
	Console.WriteLine(i);
}