Partilhar via


WordCount Application Sample

This sample shows how to create an application that opens multiple files and counts each file's bytes, characters, words, and lines. The results from each file and the total of all files are displayed.

For information about using the samples, see the following topics:

To build the sample using the command prompt

  1. Open the Command Prompt window and navigate to one of the language-specific subdirectories under the WordCount directory. For information about required settings and the SDK Command Prompt, see How to: Set Sample Settings.

  2. Type msbuild WordCountCS.sln or msbuild WordCountVB.sln, depending on your choice of programming language.

To build the sample using Visual Studio

  1. Open Windows Explorer and navigate to one of the language-specific subdirectories under the WordCount directory.

  2. Double-click the WordCountCS.sln or WordCountVB.sln file, depending on your choice of programming language, to open the file in Visual Studio 2005.

  3. On the Build menu, click Build Solution.

To run the sample

  1. In the Command Prompt window, navigate to the subdirectory that contains the WordCount application.

  2. Type WordCount.exe [filename] at the command prompt to count the words in a file.

  3. The totals from each file are listed separately and the total of the results from all the files are displayed.

Remarks

The sample is a console application; you must run it from the command line to view its output.

The sample uses the following technologies and classes:

  • I/O -

    • FileStream - Allows file access. This class is used to read to and write from files.

    • StreamWriter - Used with a FileStream instance to format text output to a file.

    • StreamReader - Used with a FileStream instance to read text from a file.

  • Collections -

    • ArrayList - Stores sets of objects.

    • SortedList - Stores sets of objects in a sorted manner.

    • IEnumerator - Enumerates over sets of objects.

    • IDictionaryEnumerator - Enumerates over indexed sets of objects.

See Also

Reference

ArrayList Class
FileStream Class
IEnumerator Interface
SortedList Class
StreamReader Class
StreamWriter Class
System.Collections Namespace
System.IO Namespace
IDictionaryEnumerator

Concepts

.NET Framework Class Library Overview

Other Resources

Overview of the .NET Framework