いくつかの面白いプログラムの問題

10601 ワード

 1:  static class Program
 2:     {
 3:         static int x, y;
 4:   
 5:         static Program()
 6:         {
 7:             // , 。 x=0,y=0
 8:             int x = 5;
 9:         }
10:   
11:         static void Main(string[] args)
12:         {
13:             //x-- x=-1
14:             x--;
15:             //
16:             myMethod();
17:             // ?x+y=1,x=x+1=2,1+2=3, 
18:             System.Console.WriteLine(x + y + ++x);
19:             Console.Read();
20:         }
21:   
22:         public static void myMethod()
23:         {
24:             //++x x=x+1=0,x++ ?y=0+0=0 ?x=x+1=1
25:             y = x++ + ++x;
26:         }
27:     }

.codearea{ color:black; background-color:white; line-height:18px; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys","BitStream Vera Sans Mono", courier,monospace,serif}
.codearea pre{ color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important}
.linewrap pre{white-space:pre-wrap; white-space:-moz-pre-wrap; white-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word; word-break:normal}
.codearea pre.alt{ background-color:#f7f7ff !important}
.codearea .lnum{color:#4f81bd;line-height:18px}
 
コードの分析を経て,最後の結果は3であった.
 
标题2:次のプログラムは何を出力しますか?
 
 1:  static void Main(string[] args)
 2:       {
 3:           bool a = true;
 4:           bool b = false;
 5:           bool c = true;
 6:   
 7:           if (a == true)
 8:               if (b == true)
 9:                   if (c == true)
10:                       Console.WriteLine("ss");
11:                   else
12:                       Console.WriteLine("we");
13:               else if (a && (b = c))
14:                   Console.WriteLine("wer");
15:               else
16:                   Console.WriteLine("were");
17:   
18:           Console.Read();
19:   
20:       }

.codearea{ color:black; background-color:white; line-height:18px; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys","BitStream Vera Sans Mono", courier,monospace,serif}
.codearea pre{ color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important}
.linewrap pre{white-space:pre-wrap; white-space:-moz-pre-wrap; white-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word; word-break:normal}
.codearea pre.alt{ background-color:#f7f7ff !important}
.codearea .lnum{color:#4f81bd;line-height:18px}
 
結果はwer.
 
标题3:以下の手順で何が表示されますか?
 1:  static void Main(string[] args)
 2:        {
 3:            char digit = 'a';
 4:            for (int i = 0; i < 10; i++)
 5:            {
 6:                switch (digit)
 7:                {
 8:                     case 'x' :
 9:                     {
10:                        int j = 0;
11:                         Console.WriteLine(j);
12:                     }
13:                     default :
14:                     {
15:                        int j = 100;
16:                        Console.WriteLine(j);
17:                     }
18:                }
19:   
20:            }
21:                int i = j;
22:                Console.WriteLine(i);
23:                Console.Read();
24:   
25:        }

.codearea{ color:black; background-color:white; line-height:18px; border:1px solid #4f81bd; margin:0; width:auto !important; width:100%; overflow:auto; text-align:left; font-size:12px; font-family: "Courier New","Consolas","Fixedsys","BitStream Vera Sans Mono", courier,monospace,serif}
.codearea pre{ color:black; line-height:18px; padding:0 0 0 12px !important; margin:0em; background-color:#fff !important}
.linewrap pre{white-space:pre-wrap; white-space:-moz-pre-wrap; white-space:-pre-wrap; white-space:-o-pre-wrap; word-wrap:break-word; word-break:normal}
.codearea pre.alt{ background-color:#f7f7ff !important}
.codearea .lnum{color:#4f81bd;line-height:18px}
 
間違いを報告します.
エラー1:この範囲内で「i」というローカル変数を宣言することはできません.これは、「i」が異なる意味を持ち、「サブ」の範囲内で他の内容を表しているためです.
エラー2:現在のコンテキストに名前「j」は存在しません.
 
Technoratiラベル:
c# ,
プログラム問題