忍者ブログ
素人が言語を学びながらクソゲーを作るブログです。
[1] [2] [3]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

using System;
using System.Collections.Generic;
using System.Text;

namespace VirtualMethods
{
public class Control
{
protected int top;
protected int left;
/* 画面上でのウィンドウの位置を決めるための式ニダー
*/
public Control(int top,int left)
{
this.top = top;
this.left = left;
}
// ウィンドウズへの描画をシミュレートするニダー
public virtual void DrawWindow()
{
Console.WriteLine("Program;プログラムを描画します。座標:{0}, {1}", top, left);
}
}
public class ListBox : Control
{
private string listBoxContents;
// 基本クラスのコンストラクタより引数が1つ増えてるニダー
public ListBox(int top, int left, string contents)
:
base(top, left) // 基本クラスのコンストラクタを呼び出しますニダー
{
listBoxContents = contents;
}
// 派生メソッドでふるまいを変えるための上書きバージョンニダー
public override void DrawWindow()
{
base.DrawWindow(); // 基本クラスのメソッドを呼び出しますニダー
Console.WriteLine("ListBoxへ文字列を書き込みます:{0}", listBoxContents);
}
}
public class Button : Control
{
public Button(int top, int left)
:
base(top, left)
{
}
// 上と似たような感じニダー

public override void DrawWindow()
{
Console.WriteLine("Buttonを描画します。座標:{0}, {1}\n", top, left);
}

}
public class Tester
{
static void Main()
{
Control win = new Control(1, 2);
ListBox lb = new ListBox(3, 4, "単独のListBox");
Button b = new Button(5, 6);
win.DrawWindow();
lb.DrawWindow();
b.DrawWindow();

Control[] winArray = new Control[3];
winArray[0] = new Control(1, 2);
winArray[1] = new ListBox(3, 4, "配列中のListBox");
winArray[2] = new Button(5, 6);

for(int i=0; i<3; i++)
{
winArray[i].DrawWindow();
}
}
}
いろいろと変更しているうちに最初のpublicを消してしまい。
アクセスシビリティがlistboxよりも下位に設定されていますとエラーがでた。



}
PR
48
// goto文 繰り返し文 経験を積んだらgotoはなるべき避けたほうがいいらしい
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class _48
{
static void main(String[] args)
{
int i = 0;
repeat:
Console.WriteLine("i: {0}, i");
i++;
if (i < 10)
goto repeat;
return;
}

}
}
// 延々と同じことを繰り返す悪夢のプログラム。失敗以前の問題。単純な例題だったらまだしもほかのコードやらなにやらある場合は保守が困難なプログラムになる。
49
// whileLoopループの文 「この条件が満たされている間はこの仕事をする」と何度も繰り返す文
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class _49
{
static void main(string args)
{
int i = 0;
while (i < 10)
{
Console.WriteLine("i:{0}", i);
i++;
}
return;
}
}
}

//次々1を足していき、それが10を超えると止まる式。
50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class _50
{
static int main(string[] args)
{
int i = 11;
do
{
Console.WriteLine("i:{0}", i);
i++;
}
while(i < 10);
return 0;
}
}
}
// 最初から条件を満たしているため、たされることもなく i=11で終了する
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class _50_2
{
static void main(string[] args)
{
for (int i = 0; i < 100; i++)
{
Console.WriteLine("{0}", i);
if (i % 10 == 0)
{
Console.WriteLine("\t{0}", i);
}
}
return;
}

}
}



忍者ブログ [PR]
カレンダー
05 2024/06 07
S M T W T F S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
フリーエリア
最新コメント
最新記事
(07/31)
48
(07/07)
49
(07/07)
50
(07/07)
(07/07)
最新トラックバック
プロフィール
HN:
フィルク・パルメ
性別:
非公開
バーコード
ブログ内検索
最古記事
(04/27)
(05/07)
(06/18)
(06/18)
(06/18)