類和類的引用/訪問private數(shù)據(jù)
namespace ConsoleApp55
{
? ? class Customer
? ? {
? ? ? ? private string name;
? ? ? ? private string address;
? ? ? ? private int age;
? ? ? ? private string createtime;
? ? ? ?
? ? ? ? public void SetAge(int age)
? ? ? ? { this.age = age ;?}
? ? ? ? public int GetAge()
? ? ? ? { return age ; }
? ? ? ? public void Show()
? ? ? ? {
? ? ? ? ? ? Console.WriteLine("名字:"+name);
? ? ? ? ? ? Console.WriteLine("地址:" + address);
? ? ? ? ? ? Console.WriteLine("年齡:" + age);
? ? ? ? ? ? Console.WriteLine("創(chuàng)建時間:" + createtime);
? ? ? ? }
? ? }
}
=====================================================
namespace ConsoleApp55
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? Customer Lisi = new Customer();
? ? ? ? ? ? Lisi.SetAge(23);
? ? ? ? ? ? Console.WriteLine(Lisi.GetAge());
? ? ? ? }
? ? }
}
