using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public const int N = 10;
static void Main(string[] args)
{
char[] word = Console.ReadLine().ToCharArray();
int i = 0, j = 0;
Console.WriteLine(word);
while ((word[i] >= 'a' && word[i] <= 'z') || (word[i] >= 'A' && word[i] <= 'Z'))
{
j++;
i++;
}
Console.WriteLine(+j);
Console.ReadLine();
}
}
}
디버깅을 시도 할 때마다 debbuger가 "IndexOutOfRangeException이 처리되지 않았습니다"라는 메시지를 표시하고 이유를 알지 못합니다.조건이있는 동안 뭐가 잘못 되었나요?
당신은'word'의 길이를 확인하지 않음 정렬. 모든 글자가 글자라면, 'i'가 배열의 끝을 넘을 때까지 루프가 계속 될 것이고 예외를 얻을 것입니다. –
팁 : 질문하기 전에 여전히 질문을하기로 결정한 경우 오류 메시지/예외 이름 (예 : https://www.bing.com/search?q=c%23+IndexOutOfRangeException)을 검색하십시오. [MCVE] 모든 필요한 정보를 인라인으로 최소한의 코드로 제공하는 가이드 라인 (이 경우''A ".ToCharArray() [1]'") –