访问修饰符 class 类名
{
//类成员:
// Methods, properties, fields, events, delegates
// and nested classes go here.
}
class Child
{
private int age;
private string name;
// Default constructor:
public Child()
{
name = "Lee";
}
// Constructor:
public Child(string name, int age)
{
this.name = name;
this.age = age;
}
// Printing method:
public void PrintChild()
{
Console.WriteLine("{0}, {1} years old.", name, age);
}
}
class StringTest
{
static void Main()
{
// Create objects by using the new operator:
Child child1 = new Child("Craig", 11);
Child child2 = new Child("Sally", 10);
// Create an object using the default constructor:
Child child3 = new Child();
// Display results:
Console.Write("Child #1: ");
child1.PrintChild();
Console.Write("Child #2: ");
child2.PrintChild();
Console.Write("Child #3: ");
child3.PrintChild();
}
}
/* Output:
Child #1: Craig, 11 years old.
Child #2: Sally, 10 years old.
Child #3: N/A, 0 years old.
*/
| Inheritance | 示例 |
|---|---|
| 无 | [code]class ClassA { }[/code] |
| Single | [code]class DerivedClass: BaseClass { }[/code] |
| 无,实现两个接口 | [code]class ImplClass: IFace1, IFace2 { }[/code] |
| 单一,实现一个接口 | [code]class ImplDerivedClass: BaseClass, IFace1 { }[/code] |
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有