開発環境
- Microsoft Windows 7 Home Premium (OS)
- Microsoft Visual C# 2010 Express Edition (IDE)
- 言語: C#
独習C# 第3版 ハーバート・シルト (著) エディフィストラーニング株式会社 矢嶋聡 (監修, 翻訳) の第6章(Cメソッドとクラスの詳細)の理解度チェック7を解いてみる。
7.
コード
using System;
public class Sample
{
public static string str;
public string str1;
public Sample(string str1)
{
this.str1 = str1;
}
public void M()
{
Console.WriteLine(str);
}
}
class Tester
{
public void Run()
{
Sample.str = "static";
Sample sample1 = new Sample("C#");
Sample sample2 = new Sample("JavaScript");
sample1.M();
sample2.M();
}
static void Main()
{
Tester t = new Tester();
t.Run();
}
}
入出力結果(Console Window)
static static 続行するには何かキーを押してください . . . .
0 コメント:
コメントを投稿