using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace getset
{
class TT
{
public int a;
public TT() { a = 10; }
}
class Test
{
public int Ilove { get; set; }
public String StuName { get; set; }
public TT TtObj { get; set; }
}
class Program
{
static void Main(string[] args)
{
Test t = new Test();
t.Ilove = 100;
t.StuName = "Lucy";
t.TtObj=new TT();
Console.WriteLine("{0} {1} {2}", t.StuName, t.Ilove,t.TtObj.a);
}
}
}
Lucy 100 10
请按任意键继续. . .
C#中属性getset的简写问题。
1
2
3
4
5
6
|
private
string
id;
public
string
ID
{
get
{
return
this
.id; }
set
{
this
.id = value; }
}
|
完全等同于
1
|
public
string
ID {
get
;
set
;}
|
简写的话,ID和id不就没关系吗?