Answer the question
In order to leave comments, you need to log in
The code doesn't work. Errors CS0161 and CS1513. What to do?
using System;
using System.Linq;
namespace project {
class Program {
public static void Main() {
Console.WriteLine(Reverse("This is an example!"));
}
public static string Reverse(string text) {
string[] arr = text.Split();
for(int i = 0; i != arr.Length; i++) {
char[] array = arr[i].ToCharArray();
Array.Reverse(array);
arr[i] = new String(array);
string result = string.Join(" ", arr);
return result;
}
}
}
Answer the question
In order to leave comments, you need to log in
1. What should this line do?
string[] arr = text.Split();
2. Show where the cycle starts and ends
public static string Reverse(string text) {
string[] arr = text.Split();
for(int i = 0; i != arr.Length; i++) {
char[] array = arr[i].ToCharArray();
Array.Reverse(array);
arr[i] = new String(array);
} // Забыл вот эту фигурную скобку
string result = string.Join(" ", arr);
return result;
}
so there was no parenthesis,
if the string length is 0 then nothing was returned to which the compiler cursed, well, look at the output of the ide, it shows where the error is
using System;
namespace project
{
class Program
{
public static void Main()
{
Console.WriteLine(Reverse("This is an example!"));
}
public static string Reverse(string text)
{
var arr = text.Split();
for (var i = 0; i != arr.Length; i++)
{
var array = arr[i].ToCharArray();
Array.Reverse(array);
arr[i] = new String(array);
var result = string.Join(" ", arr);
return result;
}
throw new ArgumentException("String must have size > 0");
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question