• ベストアンサー

C#を教えてください。

wormholeの回答

  • wormhole
  • ベストアンサー率28% (1623/5662)
回答No.10

>(" a = " + a + " b = " + b) >"+ a +"ならば"+ b +"と思うのですが 文字列 " a = " 演算子 + 変数 a 文字列 " b = " 演算子 + 変数 b この中のどこに"+ a +"なんてものが出てきますか? あなたのやってる事は、文章を変なところで区切って意味がわからないといってのと変わりません。

関連するQ&A

  • 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#の勉強を始めました。 コードは下記の通りです。 using System; class Data{ public static void main() { int a; int b; a=2; b=3; a=b; Console.WriteLine(a); } } このコードに間違いないのですが 検索してもどうやってコンパイル(実行) するのか分りません。 ご回答の程、宜しくお願い申し上げます。

  • C# デバッグモード"と"デバッグなしモードで答えが違う。

    //8が2の何乗か求めるプログラム。 using System; class Class1 {  static void Main() {   int a = (int)Math.Log(8.0,2.0);   double b = Math.Log(8.0,2.0);   if(b%1.0==0.0) Console.WriteLine("bは整数です");   else Console.WriteLine("bは整数ではありません");   Console.WriteLine("a={0} b={1}",a,b);   Console.Write("\n何かキーを押して");   Console.Read();   } } 答えはa=3 b=3.0を予想していました。 C#.Net2003でコンパイルして実行した所、 デバッグモードで実行した時の答え:  bは整数です。  a=3 b=3 デバッグなしモードで実行した時の答え:  bは整数ではありません。  a=2 b=3 でした。 ★質問1 これはC#.Net2003のバグなんでしょうか? それとも、私がデバッグモードの仕様をきちんと理解していないだけでしょうか?? ★質問2 8が2の何乗かをint型で解を取得したい場合、 (int)Math.Round(Math.Log(8.0,2.0))のようにわざわざ書かないといけないのでしょうか? 以上、アドバイスよろしくお願いします。

  • 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#のメンバ変数について

    下記のコードで enterName の変数を static void Resurut() のメソッドへの受け渡しが上手くいかず、どなたか修正点を教えて頂けないでしょうか? 【ソースコード】 static class Program { static string enterName; static int cntWin = 0; //勝利回数 static int cntLose = 0; //敗北回数 static int cntDraw = 0; //引分回数 //ユーザー名の入力 static void Main(string[] args) { string enterName = Console.ReadLine(); Console.WriteLine("ユーザ名を入力してください: {0}", enterName); Start(); Resurut(); } *一部省略 static void Resurut() { if (cntWin > cntLose) { Console.WriteLine("{0}さんの総合勝利です", enterName); } else if (cntLose > cntWin) { Console.WriteLine("CPUの総合勝利です"); } else if (cntWin == cntLose) { Console.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"); } }

  • C# マルチスレッドにおける例外処理

    下記のようなデリゲートを利用したマルチスレッドのプログラムを組みました。 しかし、マルチスレッド内で例外がおきても、正常にプログラムが終了してしまいます。 (try-catchでも例外を捕捉できません) マルチスレッドプログラムにおいて、例外を捕捉するにはどうすれば、いいのでしょうか? using System; using System.Threading; class Class1 { delegate void delg(); public static void Main() { delg d = new delg(multi); d.BeginInvoke(new AsyncCallback(call), null); //マルチスレッド開始 System.Threading.Thread.Sleep(500); //マルチスレッドで例外を強制的に投げているので、 //ここまでたどり着く前にアプリケーションが落ちるはず。 //しかし、実際には正常終了。 Console.WriteLine("メインメソッド 正常終了"); } public static void multi() { Console.WriteLine("マルチスレッドで実行中"); throw new Exception(); //例外を強制的に投げる。 } public static void call(IAsyncResult ar) { Console.WriteLine("コールバックメソッド実行"); } }

  • C#について

    using System; class AddressBook: PhoneBook { private string address; public AddressBook() : base() { address=""; } public void Input() { base.Input(); Console.Write("住所?"); string address=Console.ReadLine(); } public void Writes() { base.Write(); Console.WriteLine("住所:{0}",address); } } class kadai62 { public static void Main() { Console.Write("電話帳に入力する人数を入れてください:"); int n = int.Parse(Console.ReadLine()); AddressBook[] pb = new AddressBook[n]; int i; for (i = 0; i < pb.Length; i++) { pb[i] = new AddressBook(); Console.WriteLine("{0}番目を入力してください.", i+1); pb[i].Input(); } Console.WriteLine(); while(true) { Console.Write("どこから探しますか?[1:氏名,2:自宅電話,3:携帯電話,0:終了] "); int t = int.Parse(Console.ReadLine()); if (t == 0) break; Console.Write("探す文字列は?"); string s = Console.ReadLine(); for (i = 0; i < pb.Length; i++) { if (pb[i].Search(t, s)) pb[i].Writes(); } } } } このプログラムで public void Writes() { base.Write(); Console.WriteLine("住所:{0}",address); } のaddressが出力されません・・どうすれば 出力されますか?

  • Visual Studio 2017 C#

    いつも大変お世話になっております。 下記C#コードをVisual 2017 C#で 実行したところ 重大度レベル コード 説明 プロジェクト ファイル 行 抑制状態 エラー CS0103 現在のコンテキストに 'ConsoleWrite' という名前は存在しません。 ClassLibrary1 C:\Users\kouzo\source\repos\ClassLibrary1\ClassLibrary1\Class1.cs 19 アクティブ 重大度レベル コード 説明 プロジェクト ファイル 行 抑制状態 エラー CS0163 コントロールはひとつの case ラベル ('case 1:') から別のラベルへ流れ落ちることはできません。 ClassLibrary1 C:\Users\kouzo\source\repos\ClassLibrary1\ClassLibrary1\Class1.cs 23 アクティブ というエラーが出て実行結果が出ません。 お忙しいところ恐縮ですが、どうかご回答のほどよろしくお願いします。 using System; namespace ClassLibrary1 { public class Class1 class Program { static void Main() { int a; for (a = 5; a <= 8; a++) { ConsoleWrite(a + "÷3=" + a / 3); switch (a % 3) { case 1: Console.WriteLine(":あまりは1です。"); case 2: Console.WriteLine(":あまりは2です。"); default: Console.WriteLine(":あまりは0です。"); break; } } } } }

  • 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