C#でコンパイルできない?エラーの原因は?

このQ&Aのポイント
  • C#のベータ版をセットアップして以下のサンプルプログラムをコンパイルしたところ、エラーが発生しました。OSはWin98です。
  • プログラムリストには、C#のコンソールアプリケーションが含まれています。
  • エラーメッセージには、'System.Console' does not contain a definition for 'Writeline'と表示されています。
回答を見る
  • ベストアンサー

C#でコンパイルができない。

C#のベータ版をセットアップして以下のサンプルプログラムを コンパイルしたところ、エラーがでました。何がいけないのでしょうか?OSはWin98です。 css001.cs(7,3): error CS0117: 'System.Console' does not contain a definition for 'Writeline' using System; プログラムリスト public class CSS001 { public static void Main(string[] args) { Console.Writeline("Hello World"); } }

質問者が選んだベストアンサー

  • ベストアンサー
noname#9414
noname#9414
回答No.1

一応このエラーから考えるとSystem.Consoleには Writelineという関数を含んでいないというものと 考えられますので、関数名が違うのではないでしょうか? #C#はやっていないので、何とも言えませんが・・・ 大文字、小文字などもきちんと区別する必要があったと 思いますよ。 ではでは☆

Flat222
質問者

お礼

ありがとうございます。 WritelineをWriteLineにした("L"を大文字にした)ところ コンパイルできました。 C#からC言語を始める初心者なもので、こんなところで つまずいてしまいましたが、おかげさまで勉強になりました。

関連するQ&A

  • C#についての質問です

    Microsoft Visual C# 2010 Express をつかって using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Console { class Program { static void Main(string[] args) { Console.WriteLine("皆様、はじめまして"); } } } と入力して.csで保存したのですが、コマンドプロンプトで 'csc' は、内部コマンドまたは外部コマンド、 操作可能なプログラムまたはバッチ ファイルとして認識されていません。 とでてコンパイルできません。対応を教えてください。

  • C# この文法でコンパイルが通らないのは何故?

    下記のような2つのプログラムがあり、一方はコンパイルが通らず、もう一方はコンパイルが通ります。 文法上の違いはさほどないと思うのですが、何故このような結果になるのでしょうか? /////////////////////////コンパイルNG///////////////////////// using System; class Class1{ public static void Main(){ Class2 x; //違い! Class2 xをここで定義 try{x = new Class2(100);} catch{} Console.WriteLine(x.z); } } class Class2{ public int z; public Class2(int x){ z=x; } } /////////////////////////////////////////////////////////// /////////////////////////コンパイルOK///////////////////////// using System; class Class1{ static Class2 x; //違い! Class2 xをここで定義 public static void Main(){ try{x = new Class2(100);} catch{} Console.WriteLine(x.z); } } class Class2{ public int z; public Class2(int x){ z=x; } } ///////////////////////////////////////////////////////////

  • C#の変数の範囲

    C#の変数の範囲 質問させてください。 以下は、ネットに掲載されていたC#の問題です。 ~ここから~ 下記のC#のコードを実行した場合、"Hello World!"と二行表示されます。 using System; class Program { static void Main(string[] args) { string s = "Hello"; Action a = () => Console.WriteLine(s); s += " World!"; a(); Console.WriteLine(s); } これを一行目だけ"Hello"と表示される場合、 Action a = () => Console.WriteLine(s);をどう書き換えればよいでしょうか。 1. Action a = () => Console.WriteLine("Hello!"); 2. Action<string> a = (s) => Console.WriteLine(s); 3. Action a = () => Console.WriteLine(t - " World!"); 4. string t = s; Action a = () => Console.WriteLine(t); 5. Action a = () => { string t = s; Console.WriteLine(t); }; ~ここまで~ 正解は4だそうですが、「何故」そうなるかがわかりません。 汗 私としては、1.4.も題意を満たす気がするのですが・・・。 お知恵をお貸しください。 出展 http://www.atmarkit.co.jp/fdotnet/extremecs/extremecs_07/extremecs_07_10.html

  • Visual C++ 2008 Express Editionで作ったプログラムがコンパイルできない

    http://www.asahi-net.or.jp/~yf8k-kbys/newcpp3.html このサイトに掲載されていたプログラムをまねて以下のプログラムをかいてみたのですがコンパイルが通りません。 原因などはどこにあるのか教えていただけないでしょうか。 // test003.cpp : メイン プロジェクト ファイルです。 #include "stdafx.h" //using namespace System; using namespace std; int main(array<System::String ^> ^args) { string name; //Console::WriteLine(L"Hello World"); //return 0; cout << "こんにちは。私はコンピュータです。" << endl; cout << "あなたの名前を入力してください。" << endl; cin >> name; cout << name <<"さん。よろしく。" << endl; }

  • Visual C++ 2008 Express Editionの”hello worldのプログラム”

    CUIのプロジェクト作成で自動的に // cui_test.cpp : メイン プロジェクト ファイルです。 #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); return 0; } このようなプログラミングができて一つ疑問ができたのですが、 ”Console::WriteLine(L"Hello World");” System::Console:: のメソッドの中にある ”WriteLine(L"Hello World");” なぜ”(L"Hello World")”という引数の書き方をしているのですか? ”L”と”"Hello World"”というのは別々の引数として登録しているのでしょうか? オブジェクトブラウザでSystem::Console:: WriteLineを検索したのですが、18種類あってどれを使っているのかわかりません。 教えてくださいよろしくお願いいたします。

  • パイプを用いた通信 C#とMATLAB

    パイプを使用しC#から送信したデータをMATLABで受信することは可能でしょうか?   もし可能であるならばどのようにすればよいのでしょうか。 以下のプログラムで行っているのですがMATLAB側で受信ができず -1がかえってきてしまいます C言語で受信する場合はうまくいくのですがMATLABを使用するとファイルのopneができません。 以下C#・MATLABプログラム C# <プログラム> 送信側 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO.Pipes; using System.IO; namespace PipeTest { class Program { static void Main(string[] args){ Console.WriteLine("パイプ接続待ち..."); NamedPipeServerStream pipe = new NamedPipeServerStream("test"); pipe.WaitForConnection(); Console.WriteLine("送信(キーを押すと終了)"); StreamWriter stw = new StreamWriter(pipe); stw.AutoFlush = true; while(Console.KeyAvailable == false) { stw.WriteLine("This is a test"); System.Threading.Thread.Sleep(500); } Console.WriteLine("終了"); pipe.Close(); } } } MATLAB <プログラム> 受信側 fp = fopen('C:\\\\.\\pipe\\test');

  • Visual Studio 2017C#

    下記のVisual Studio 2017 C# 19行目のXの定義がありません。 と出ました。 11行目で定義していると思うのですけど…。 どういうことなのか教えてください。 ご多忙のところ恐れ入りますが、ご回答のほどよろしくお願いします。 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace jump25 { class Test { public int x = 10; } class Program { public static void Main(string[] args) { Test obj = new Test(); int y = object.x; Console.WriteLine(y); } } }

  • C#のコマンドラインの分割コンパイルと実行について

    コマンドラインでC#のプログラムをコンパイルと実行する方法 mainが1つでsubが1の場合は以下にある。 http://d.hatena.ne.jp/taka_2/20080124/p6 mainが1つでsubが2つの場合はコマンドはどうするか。 以下に使用したコマンドを示す csc /target:library sub1.cs csc /target:library sub2.cs csc /R:sub1.dll /R:sub2.dll main1.cs とすると error CS0246: 型または名前空間名 'sub1' が見つかりませんでした。using ディレクティブまたはアセンブリ参照が不足しています。 のエラーメッセージが表示される。 わかっている方がおりましたら、教えて下さい。 以下にプログラムを示す。 //---------------------------------------------------------------------------- // mainファイルの内容 using System ; using System.Text; using System.IO; using sub1 ; // subの名前空間を指定(分割コンパイル用) using sub2 ; // subの名前空間を指定(分割コンパイル用) namespace main1 { class Program { static void Main(string[] args) { int a = 10 ; int b = 5 ; sub1.dfsub_cs1 df1 = new sub1.dfsub_cs1() ; // sub1のクラスを確保(分割コンパイル用) sub2.dfsub_cs2 df2 = new sub2.dfsub_cs2() ; // sub2のクラスを確保(分割コンパイル用) Console.Write("add {0,3:D} * {1,3:D} = {2,5:D}\n", a,b, df1.multiply( a, b) ); Console.Write("add {0,3:D} / {1,3:D} = {2,5:D}\n", a,b, df2.divide( a, b) ); return ; } } } //---------------------------------------------------------------------------- // sub1ファイルの内容 namespace sub1 { public class dfsub_cs1 { public int multiply(int a, int b ) { return a * b ; } } } //---------------------------------------------------------------------------- // sub2ファイルの内容 namespace sub2 { public class dfsub_cs2 { public int divide(int a, int b ) { return a / b ; } } }

  • クライアント上のC++でサーバーとソケット送信

    クライアント(Windows7)上でC++を使って、サーバー側(Windows)に対してデータを送りたいです (ソケット通信?)。 サーバ受信側はC#を使ったプログラムで以下のような感じで考えてます。 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Net.Sockets; using System.IO; namespace ConsoleApplication1 {   class Program   {     static void Main(string[] args)     {       int port = 2222;       System.Net.IPAddress ip = IPAddress.Parse("127.0.0.1");       System.Net.Sockets.TcpListener server = new TcpListener(ip, port);       Console.WriteLine("Enter押してください");       ConsoleKeyInfo info = Console.ReadKey();       if (info.Key == ConsoleKey.Enter)       {         Console.WriteLine("サーバー待機中");         server.Start();         TcpClient client = server.AcceptTcpClient();         NetworkStream ns = client.GetStream();         StreamWriter sw = new StreamWriter(ns);         Console.WriteLine(sw);       }     }   } } C++のことがよくわかってないので、送信側でC++を使ってどのように 送信すればいいのかわかりません。 送信するデータはINT型で、1秒間に1回、繰り返し送ります。 よろしくお願いします。

  • C#のXmlDocumentについて

    C#のXmlDocumentについて質問です。 using System; using System.Xml; using System.Windows; public class XmlNewClass{ public static void Main(String [] args){ XmlDocument xmlObj = new XmlDocument(); xmlObj.Load("./test.xml"); XmlNode nodeObj = xmlObj.GetElementsByTagName("root").Item(0); Console.WriteLine(nodeObj); } } 上記のようなコードがあったとします。 この場合、プロンプトに表示されるないようは 〔System.Xml.XmlElement〕という記述が出力されます。 次に XmlElement elementObj =nodeObj; というコードを追加したとします。 それを実行してみると /****************************************************************** xml.cs(21,26): error CS0266: 型 'System.Xml.XmlNode' を 'System.Xml.XmlElement' に暗黙的に変換できません。明示的な変換が存在します。(cast が不足していないかどうかを確認してください) ***************************************************************************/ というようなエラーがプロンプト上に表示されます。 これはnodeObjがXmlNodeというクラスだということですが (実際GetElementsByTagNameで帰って来るオブジェクトはXmlNodeというクラスだとマニュアルにも記載がありました) なぜ冒頭のコードで Console.WriteLine(nodeObj); の箇所の出力で〔XmlElement〕という内容が出力されたのでしょうか? 同じオブジェクトなのに、なぜ出力と型がことなるのでしょうか? ご教授よろしくお願いします。

専門家に質問してみよう