0
我試圖計算平均字長,但我不斷收到錯誤出現。如何計算平均字長
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using System.Text;
namespace textAnalyser
{
public class Analyser
{
public static void Main()
{
// Values
string myScen;
string newScen = "";
int numbChar = 0;
string userInput;
int countedWords = 0;
//User decsion on how to data is inputted
Console.WriteLine("Enter k for keyboard and r for read from file");
userInput = Convert.ToString(Console.ReadLine());
//If statement, User input is excecuted
if (userInput == "k")
{
// User enters their statment
Console.WriteLine("Enter your statment");
myScen = Convert.ToString(Console.ReadLine());
// Does the scentence end with a full stop?
if (myScen.EndsWith("."))
Console.WriteLine("\n\tScentence Ended Correctly");
else
Console.WriteLine("Invalid Scentence");
計算的字符數一句話
// Calculate number of characters
foreach (char c in myScen)
{
numbChar++;
if (c == ' ')
continue;
newScen += c;
}
Console.WriteLine("\n\tThere are {0} characters. \n\n\n", numbChar);
// Calculates number of words
countedWords = myScen.Split(' ').Length;
Console.WriteLine("\n\tTherer are {0} words. \n\n\n", countedWords);
這是我試圖計算平均字長 //計算平均字長
double averageLength = myScen.Average(w => w.Length);
Console.WriteLine("The average word length is {0} characters.", averageLength);`}
你看到的錯誤是什麼? – Beska
'char'不包含'length'的定義,並且沒有可以找到'char'類型的第一個參數的擴展方法長度<是否缺少using指令或程序集引用:> – user1832076