码迷,mamicode.com
首页 > Windows程序 > 详细

【C#学习笔记】类构造函数使用

时间:2017-08-27 16:15:00      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:span   static   sys   int()   read   stat   log   string   code   

using System;

namespace ConsoleApplication
{
    class stu
    {
        private string name;
        private int age;

        public stu()
        {
            name = "";
            age = -1;
        }

        public stu(string n, int a)
        {
            name = n;
            age = a;
        }

        public void Print()
        {
            Console.Write(name + ":" + age);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            stu a=new stu("xiaoming",10);
            a.Print();

            Console.WriteLine();
            stu b = new stu();
            b.Print();

            Console.Read();
        }      
    }
}

 

【C#学习笔记】类构造函数使用

标签:span   static   sys   int()   read   stat   log   string   code   

原文地址:http://www.cnblogs.com/tiandsp/p/7440428.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!