復制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Text;
namespace 屬性的用法
{
public class Student
{
private string stuCollege = "jyu";//學校名稱不可修改
private string stuName = "阿會楠";
private int stuAge = 22;
public string studentName
{
get { return stuName; }
set { stuName = value; }
}
public int studentAge
{
get { return stuAge; }
set { stuAge = value; }
}
public string studentCollege
{
get { return stuCollege; }
}
public string studentInfo
{
get { return "學校:" + stuCollege + "名字:" + stuName + "歲數:" + stuAge;}
}
}
class Program
{
static void Main(string[] args)
{
Student stu = new Student();
Console.Write(stu.studentCollege + "/n");
stu.studentAge = 25;
Console.Write(stu.studentInfo);
Console.ReadKey();
}
}
}
新聞熱點
疑難解答
圖片精選