이것은 기본 문자열 역방향 프로그램이므로 일부 예외 처리 수준에서 수행하려고합니다. 그러나 그것은 나에게 오류를 제공 컴파일시 "모든 코드 경로는 값을 반환합니다. 내가 왜C# 컴파일러에서 모든 코드 경로가 값을 반환하지 않습니다.
public static string Reverse(string s)
{
try
{
if (string.IsNullOrEmpty(s))
{
throw new NullReferenceException();
}
char[] c = s.ToCharArray();
int start = 0;
int end = c.Length - 1;
char temp;
while (start < end)
{
temp = c[start];
c[start] = c[end];
c[end] = temp;
start++;
end--;
}
return new string(c);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
고마워을 찾을 수 없습니다 나는 ... 나는이
public static string Reverse(string s)
{
if (!string.IsNullOrEmpty(s))
{
char[] c = s.ToCharArray();
int start = 0;
int end = c.Length - 1;
char temp;
while (start < end)
{
temp = c[start];
c[start] = c[end];
c[end] = temp;
start++;
end--;
}
return new string(c);
}
else return s;
}
작은 비판을 다음과 같이 될 수있는 일을하는 청소기 방법 : 매개 변수가 null의 경우 던지거나 빈 문자열을 반환해야 하나. null을 전파하는 것은 그다지 유용하지 않습니다 (이 경우). –