2016-10-24 3 views
-1

Windows 콘솔 응용 프로그램을 사용하여 문장의 단어 수를 계산하려고합니다. 하지만 배열 것은 새로운이야 정말 내가 그 코드로 무엇을 할 수 있는지 모른다 : (단어 == 공간 사이의 모든 문자는) 당신이 뭔가를 구현할 수 쉬운 경우에서System.Array에 길이 정의에 대한 정의가 없습니다

string sentence; 
Console.WriteLine("Enter your sentence:"); 
sentence = Console.ReadLine(); 

string [] words = sentence.Split(' '); 
Console.WriteLine(sentence.Lenght); // .Lenght is where I get the error from 
Console.ReadKey(); 
+2

철자를 잘못 입력 했으므로 '길이'입니다. – Equalsk

+2

길이가 철자로되어 있는데, 길이는 아닙니다. –

+2

문자열에'Length'를 : 배열에'문장'이 아닌'words'라고 부릅니다. 그것은 012.All입니다. Console.WriteLine (words.Length);' – croxy

답변

1

같은 : 내가 어떤 맞춤법 오류가 있다면 제대로 길이 단어의 철자 때 나는 here.Now 게시하기 전에

Console.WriteLine("Enter your sentence:"); 

// try not declaring local variable prematurely, but exacly where you want them 
string sentence = Console.ReadLine(); 

// StringSplitOptions.RemoveEmptyEntries - what if user starts with space? 
// separate words with two spaces, e.g. " This is a test input " 
// we want 5, right? 
int count = sentence 
    .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) 
    .Length; // Please, notice spelling 

Console.WriteLine(count); 

Console.ReadKey(); 
0

임은 정말 바보 그것은 덕분에, 사람을 works.Sorry하지만, 확인하지합니다.

관련 문제