まずは、C#をインストールしなければなりません。2001年2月現在、MSDN Online .NET Informationから.NET Framework SDK Beta 1 日本語版をダウンロードすることができます。これをインストールすることによって、C#コンパイラが使用できるようになります。必要とする環境は、Internet Explorer 5.5およびData Access Components 2.6がインストールされているWindows 2000/NT/98/Meです。また、あくまでβ版なので、これを用いた際の保証はされていません。
2004年6月現在、C#コンパイラは正式にリリースされており、Microsoft .NET Frameworkのウェブページから.NET Framework SDK Version 1.1およびMicrosoft .NET Framework Version 1.1 再頒布可能パッケージをインストールすることで使用できます。更に、SharpDevelopによりフリーの.NET開発環境を用意することもできます。加えて、SharpDevelop-jpが提供する日本語環境も使用できます。
また、UnixなどのWindows以外のOSでも、Mono Projectのウェブサイトから.NET互換環境であるMonoをダウンロードすることでC#コンパイラなどが使用できます。因みに、日本語化されたサイトもあります。
さて、インストールが無事終わったならば、C#コンパイラが使えるか確認しましょう。コマンドライン上でcsc
と打ち込んで、以下のようなメッセージが出れば成功です。
>csc Microsoft (R) Visual C# Compiler Version 7.00.9030 [CLR version 1.00.2204.21] Copyright (C) Microsoft Corp 2000. All rights reserved. Visual C# Compiler Options - OUTPUT FILES - /out:<file> Output file name (derived from first source file if not specified) /target:exe Build a console executable (default) (Short form: /t:exe) /target:winexe Build a windows executable (Short form: /t:winexe) /target:library Build a library (Short form: /t:library) /target:module Build a module that can be added to another assembly (Short form: /t:module) /nooutput[+|-] Only check code for errors; do not emit executable /define:<symbol list> Define conditional compilation symbol(s) (Short form: /d) /doc:<file> XML Documentation file to generate - INPUT FILES - /recurse:<wildcard> Incude all files in the current directory and subdirectories according to the wilcard specifications /main:<type> Specifies the type that contains the entry point (ignore all other possible entry points) (Short form: /m) /reference:<file list> Reference metadata from the specified assembly files (Short form: /r) /addmodule:<file list> Link the specified modules into this assembly - RESOURCES - /win32res:<file> Specifies Win32 resource file (.res) /win32icon:<file> Use this icon for the output /resource:<resinfo> Embeds the specified resource (Short form: /res) /linkresource:<resinfo> Links the specified resource to this assembly (Short form: /linkres) - CODE GENERATION - /debug[+|-] Emit debugging information /debug:{full|pdbonly} Specify debugging type ('full' is default, and enables attaching a debugger to a running program) /optimize[+|-] Enable optimizations (Short form: /o) /incremental[+|-] Enable incremental compilation (Short form: /incr) - ERRORS AND WARNINGS - /warnaserror[+|-] Treat warnings as errors /warn:<n> Set warning level (0-4) (Short form: /w) /nowarn:<warning list> Disable specific warning messages - LANGUAGE - /checked[+|-] Generate over/underflow checks /unsafe[+|-] Allow 'unsafe' code - MISCELLANEOUS - @<file> Read response file for more options /help Display this usage message (Short form: /?) /nologo Suppress compiler copyright message - ADVANCED - /baseaddress:<address> Base address for the library to be built /bugreport:<file> Create a 'Bug Report' file /codepage:<n> Specifies the codepage to use when opening source files /fullpaths Compiler generates fully qualified paths /nostdlib[+|-] Do not reference standard library (mscorlib.dll) |
そして、C#のプログラムはソースファイルの拡張子を".cs"として保存し、例えば、test.csというファイル名にしたならば、それをコンパイルするためには、csc test.cs
とすればよいわけです。
では、次の節で早速プログラミングをしていきましょう。