【发布时间】:2014-05-04 21:50:01
【问题描述】:
在这些类型的类中,我可以将类 ListBox 设为部分类吗?如果是的话,有人可以给我看一些例子。如果不是,您能简单解释一下原因吗?
namespace example
{
public class Control
{
private int top;
private int left;
public Control(int Top, int Left)
{
top = Top;
left = Left;
}
public void DrawControl()
{
Console.WriteLine("Drawing Control at {0}, {1}", top, left);
}
}
// how to make this class ListBox a partial class?
public class ListBox: Control
{
private string mListBoxContents;
public ListBox(int top, int left, string theContent): base(top,left)
{
mListBoxContents = theContent;
}
public new void DrawControl()
{
base.DrawControl();
Console.WriteLine("Writing string to the ListBox: {0}", mListBoxContents);
}
}
public class Tester
{
public static void Main()
{
Control myControl = new Control (5,10);
myControl.DrawControl();
ListBox lb = new ListBox (20, 30, "Hello World");
lb.DrawControl();
}
}
}
【问题讨论】:
标签: c# partial-classes