类的创建于使用

【知识梳理】
- 类是一个抽象的存在,就像工业生产中的图纸一样
- 构造函数是一个类的初始化过程

【课堂要求】
- 大致了解类的概念
- 了解构造函数的作用

using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            person people = new person();
            Console.WriteLine("请输入我的姓名");
            people.name = Console.ReadLine();
            Console.WriteLine("请输入我的年龄");
            people.age = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入我的性别");
            people.sex = char.Parse(Console.ReadLine());
            Console.WriteLine("大家好,我使用的是构造函数,我叫{0},今年{1}岁了,是个{2}孩。", people.name, people.age, people.sex);
            person1 people1 = new person1("小金", 33, '');
            Console.WriteLine("大家好,我使用的是构造函数的重载,我叫{0},今年{1}岁了,是个{2}孩。", people1.name, people1.age, people1.sex);
        }
    }
    /// <summary>
    /// 构造函数重载
    /// </summary>
    class person1
    {
        public string name;
        public int age;
        public char sex;
        public person1(string name, int age, char sex)
        {
            this.name = name;
            this.age = age;
            this.sex = sex;

        }
    }
    /// <summary>
    /// 系统默认自动构造
    /// </summary>
    class person
    {
        public string name;
        public int age;
        public char sex;
    }
}
原文地址:https://www.cnblogs.com/BruceKing/p/11739204.html