Por que eu não consigo imprimir essa string
de forma reversa? Eu sei que há possibilidade de usar outra forma mais simples, porém quero entender o erro.
static void Main(string[] args)
{
string frase = "Diego lima de Aquino";
for(int i = frase.Length; i>=0; i--)
{
Console.WriteLine(frase[i]);
}
Console.ReadKey();
}
Erro:
System.IndexOutOfRangeException was unhandled HResult=-2146233080 Message=Index was outside the bounds of the array. Source=mscorlib StackTrace: at System.String.get_Chars(Int32 index) at AppNoPrompt_1.Program.Main(String[] args) in C:\Users\Diegolaquino\documents\visual studio 2015\Projects\AppNoPrompt_1\AppNoPrompt_1\Program.cs:line 20 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: