Advertisement

C#基础——构造函数

阅读量:
复制代码
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Constructor
    {
    class Dog
    {
        //构造函数,等价于默认构造函数
        public Dog()
        {
            System.Console.WriteLine("\tDog():{0}---{1}", this._Name, this._Weight);
            this._Weight = 20;
        }
    
        //带参数构造函数,初始化姓名和体重
        public Dog(string name, int wt)
        {
            System.Console.WriteLine("\tDog():{0}---{1}", this._Name, this._Weight);
            this._Name = name;
            this._Weight = wt;
        }
    
        //姓

全部评论 (0)

还没有任何评论哟~