c#类的初使用

来源:互联网 发布:癌症晚期知乎 编辑:程序博客网 时间:2024/04/30 15:54
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            Person p1 = new Person();            p1.showperson();            Person p2 = new Person("zangyunji", 20);            p2.showperson();            Console.ReadKey();        }    }    public class Person    {        public string name;        int age;        protected string sex;        public Person()        {        }        public Person(string s, int a)        {            name = s;            age = a;        }        public void showperson()        {            Console.WriteLine("name:{0} age:{1}", name, age);        }    }}

0 0
原创粉丝点击