4、结构和类均为引用类型
5、 属性必须同时定义get块和set块。 6、构造函数和析构函数均可以被显式调用。
7、在C#中,每个方法都必须定义为类或结构的成员。
8、在一个程序内,不可以包含2个及以上的Main方法。 9、 用ref修饰符声明的形参是引用形参。
10、 可以不使用new关键字来对数组进行初始化( ) 四、读程序写结果 1、class Program
{
static void Main(string[] args) {
B b = new B(); A a = b; a.G(); b.G();
Console.Read(); } }
class A {
public virtual void G() {
Console.Write (\ } }
class B : A {
public override void G() {
Console.Write (\ } }
程序的输出结果是_____________________________ 2、 static void Main(string[] args)
{
try {
int x = Convert.ToInt32(Console.ReadLine()); int y = Convert.ToInt32(Console.ReadLine()); int z = x / y; }
catch (FormatException)
{Console.WriteLine(\格式不符\ catch (DivideByZeroException)
{ Console.WriteLine(\除数不能是0\ catch (Exception)
{Console.WriteLine(\ finally {
Console.WriteLine(\
}
Console.ReadLine(); }
若分别从键盘上输入5和x,则程序的最终执行结果是
3、写岀下面程序的运行结果 class Program {
static void Main(string[] args) {
Class1 c1 = new Class1(); Class1.y = 5; c1.output();
Class1 c2 = new Class1(); c2.output();
Console.ReadLine(); } }
public class Class1 {
private static int x = 0; public static int y = x; public int z = y; public void output() {
Console.Write (Class1.x); Console.Write (Class1.y); Console.Write (z); } }
五、综合题
1、类和对象的区别和关系是什么? 2、构造函数有哪些特征?
3、编程实现判断某一年是否是闰年。
4、编写一个信息类information。使用shezhi方法设置会员的姓名、年龄、学校信息。使用xianshi方法将会员的姓名、年龄、学校信息显示出来。
相关推荐: