c#类的初使用

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);
        }
    }
}

你可能感兴趣的:(c#类的初使用)