摘要: 要扩展或修改继承的方法、属性、索引器或事件的抽象实现或虚实现,必须使用 override 修饰符。在此示例中,Square 类必须提供 Area 的重写实现,因为 Area 继承自抽象的 ShapesClass:abstract class ShapesClass{ abstract public int Area();}class Square : ShapesClass{ int side = 0; public Square(int n) { side = n; } // Area method is required to avoid ... 阅读全文
posted @ 2013-01-23 13:55 447726527 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 类是使用关键字 class 声明的,如下面的示例所示:class TestClass{ // Methods, properties, fields, events, delegates // and nested classes go here.}下面的示例说明如何声明类的字段、构造函数和方法。该例还说明了如何实例化对象及如何打印实例数据。在此例中声明了两个类,一个是 Child 类,它包含两个私有字段(name 和 age)和两个公共方法。第二个类 TestClass 用来包含 Main。class Child{ private int age; private ... 阅读全文
posted @ 2013-01-23 13:50 447726527 阅读(274) 评论(0) 推荐(0) 编辑
摘要: bool 关键字是 System.Boolean 的别名。它用于声明变量来存储布尔值 true 和 false。可将布尔值赋给 bool 变量。也可以将计算为 bool 类型的表达式赋给 bool 变量。public class BoolTest{ static void Main() { bool b = true; // WriteLine automatically converts the value of b to text. Console.WriteLine(b); int days = DateTime.Now... 阅读全文
posted @ 2013-01-23 13:46 447726527 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 如果类实现两个接口,并且这两个接口包含具有相同签名的成员,那么在类中实现该成员将导致两个接口都使用该成员作为它们的实现。例如:interface IControl{ void Paint();}interface ISurface{ void Paint();}class SampleClass : IControl, ISurface{ // Both ISurface.Paint and IControl.Paint call this method. public void Paint() { }}然而,如果两个接口成员执行不同的函数,那么这可能会导致... 阅读全文
posted @ 2013-01-22 18:51 447726527 阅读(323) 评论(0) 推荐(0) 编辑
友荐云推荐