using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 属性的扩展
{
class Program
{
static void Main(string[] args)
{
classA A = new classA();
A.Age = "18";
A.Name = "谢文林";
indexA<string> a = new indexA<string>();
a[0] = "AAAAA";
Console.WriteLine("我出生于{0}年", A.生日1);
Console.WriteLine(A.Name);
Console.WriteLine(A.Age);
Console.WriteLine(a[0]);//获取值
Console.ReadKey();
}
}
public class classA
{
private string name;
public string Name
{
get { return name + "男士"; }
set { name = value; }
}
private int 生日;
public int 生日1
{
get
{
int Iage = Convert.ToInt32(age.Replace("周岁",""));//去取值
int year = DateTime.Now.Year;
return year - Iage;//获得当前的岁数
}
}
string age;
public string Age
{
get { return age; }
set { age = value + "周岁"; }
}
}
public class indexA<T>//索引器
{
T[] t = new T[1000];
public T this[int i]
{
get { return t[i];}//得到值
set { t[i]= value;}
}
}
}
属性及一些基本的操作
最新推荐文章于 2020-03-13 21:25:56 发布