using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _02面向对象{ class Program { static void Main(string[] args) { //Person p = new Person(); //p.Name = "小王"; //p.Age = 19; //p.Gender = '男'; //p.SayHello(); for (int i = 0; i < 1000000; i++) { Console.WriteLine(i); } Console.ReadKey(); } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace _02面向对象{ // 首先特征:字段 // 行为:方法 class Person { private string name; int age; // ctrl + r + e快速得到字段对应的属性 char gender; public void SayHello() { Console.WriteLine("大家好,我叫{0},今年{1}岁了,我是{2}生", name, age, gender); } public string Name { get { return name; } set { name = value; } } public int Age { get { return age; } set { age = value; } } public char Gender { get { return gender; } set { gender = value; } } }}