忍者ブログ
素人が言語を学びながらクソゲーを作るブログです。
[14] [13] [12] [11] [10] [9]
×

[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

コメント


コメントフォーム
お名前
タイトル
文字色
メールアドレス
URL
コメント
パスワード
  Vodafone絵文字 i-mode絵文字 Ezweb絵文字


トラックバック
この記事にトラックバックする:
HOME 48>>


忍者ブログ [PR]
カレンダー
06 2024/07 08
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 31
フリーエリア
最新コメント
最新記事
(07/31)
48
(07/07)
49
(07/07)
50
(07/07)
(07/07)
最新トラックバック
プロフィール
HN:
フィルク・パルメ
性別:
非公開
バーコード
ブログ内検索
最古記事
(04/27)
(05/07)
(06/18)
(06/18)
(06/18)