110,535
社区成员
发帖
与我相关
我的任务
分享
class Men
{
private int id;
public int Id
{
get { return id; }
set { id = value; }
}
public Men(int c)
{
this.Id = c;//属性
this.id = c;//私有字段
}
}
using System;
using System.Collections.Generic;
using System.Text;
class Class1
{
private string value1;
public string Value1
{
get { return value1; }
set { value1 = value; }
}
public string Test1()
{
long vTickCount = Environment.TickCount;
for (int i = 0; i < 10000000; i++)
this.value1 = i.ToString();
return string.Format("私有字段: {0} MSEL", Environment.TickCount - vTickCount);
}
public string Test2()
{
long vTickCount = Environment.TickCount;
for (int i = 0; i < 10000000; i++)
this.Value1 = i.ToString();
return string.Format("属性: {0} MSEL", Environment.TickCount - vTickCount);
}
}
class Program
{
static void Main(string[] args)
{
Class1 tmpObj = new Class1();
Console.WriteLine(tmpObj.Test1());
Console.WriteLine(tmpObj.Test2());
Console.ReadLine();
}
}
你这个看不出来,看下面的
private int age;
public int Age
{
get { return age; }
set
{
if (value >= 0 && value <= 150)
age = value;
else
age = 18;
}
}