I am getting a couple of build errors in my code.
The first of which is:
'wordFreq' is a 'variable' but is used like a 'method'
it says that on the line:
wordFreq(words[i].ToLower()) += 1;
I am also getting an error that says:
The name ' i ' does not exist in the current context
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections;
namespace ConsoleApplication2
{
class SplitTextFile
{
static void Main(string[] args)
{
FileStream file = new FileStream("input.txt", FileMode.OpenOrCreate, FileAccess.Read);
StreamReader sr = new StreamReader(file);
string s = sr.ReadToEnd();
sr.Close();
file.Close();
char[] delim = { ' ', '\t', '\r', '\n' };
string[] words = s.Split(delim);
Hashtable wordFreq = new Hashtable();
foreach (string word in words)
{
if (words[i] != "")
{
bool realWord = true;
for (int j = 0; j < words[i].Length; j++)
{
if (char.IsLetter(words[i][j]) == false)
{
realWord = false;
}
}
if (realWord == true)
{
if (wordFreq.Contains(words[i].ToLower()))
{
wordFreq(words[i].ToLower()) += 1;
}
else
{
wordFreq.Add(words[i].ToLower(), 1);
}
}
}
}
SortedList wordCount = new SortedList();
foreach (DictionaryEntry de in wordFreq)
{
if (wordCount.ContainsKey(de.Value) == false)
{
wordCount.Add(de.Value, de.Key);
}
}
}
}
}